java – 为什么不同的长值转换为相同的日期/时间?
发布时间:2020-12-15 02:00:35 所属栏目:Java 来源:网络整理
导读:public static void getTime() { SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Time t1 = new Time(Long.parseLong("1369213412435")); Time t2 = new Time(Long.parseLong("1369213412245")); System.out.println(sdf.format(t1)
public static void getTime() { SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Time t1 = new Time(Long.parseLong("1369213412435")); Time t2 = new Time(Long.parseLong("1369213412245")); System.out.println(sdf.format(t1)); System.out.println(sdf.format(t2)); } 为什么打印上面的代码, 2013-05-22 17:03:32 2013-05-22 17:03:32 解决方法
这两个日期的差别仅为毫秒(435或245),您可以在格式中忽略这些日期.
使用: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); 看到不同的价值观. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |