我花了几个小时才能了解代码中TimeStamp
的情况。
Oracle DB和Java应用程序都在PDT中
从数据库中选择:
select id, time_stamp from some_Table where id = '3de392d69c69434eb907f1c0d2802bf0';
3de392d69c69434eb907f1c0d2802bf0 09-DEC-2014 12.45.41.354000000 PM
select id, time_stamp at time zone 'UTC' from some_Table where id = '3de392d69c69434eb907f1c0d2802bf0';
3de392d69c69434eb907f1c0d2802bf0 09-DEC-2014 12.45.41.354000000 PM
Oracle数据库中的字段为
TimeStamp
,因此不会存储任何时区信息。Timestamp dbTimeStamp = dbRecord.getLastLoginTime();
System.out.println(dbTimeStamp.toString()); // 2014-12-09 12:16:50.365
System.out.println(dbTimeStamp.getTime()); // 1418156210365 --> Tue Dec 09 2014 20:16:50 UTC?
根据documentation,
getTime()
返回自格林尼治标准时间1970年1月1日00:00:00以来的毫秒数
由此Timestamp对象表示。
为什么将
8 hours (PDT - UTC)
多余的时间添加到getTime()
的响应中? 最佳答案
TimeStamp.toString()
在内部使用Date.getHours()
,其javadoc指出:
返回此Date对象表示的小时。的
返回值是一个数字(0到23)
表示包含或开始的一天中的小时
与此日期表示的时间点
对象,以当地时区解释。
因此,toString
使用的是您的本地时区,而getDate
没有使用。