为什么不同的长值转换成相同的日期/时间? [英] Why are different long values converted into the same date/time?

查看:148
本文介绍了为什么不同的长值转换成相同的日期/时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public static void getTime(){
SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);
时间t1 =新时间(Long.parseLong(1369213412435));
时间t2 =新时间(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),您在格式中忽略。 p>

使用:

  SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM- dd HH:mm:ss SSS); 

查看不同的值。


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));
}

Why does the above code prints,

2013-05-22 17:03:32
2013-05-22 17:03:32

解决方案

The two dates differ only by milliseconds (435 or 245), which you ignore in your format.

Use:

 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");

to see the different values.

这篇关于为什么不同的长值转换成相同的日期/时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆