可以说我有一个时间戳记值。Timestamp.getTime()将时间戳值视为系统时区中的时间
编辑
Calendar curCal = new GregorianCalendar(TimeZone.getDefault());
curCal.setTimeInMillis(System.currentTimeMillis());
TimeZone fromTz = TimeZone.getDefault();
curCal.setTimeZone(fromTz);
TimeZone gmtTZ = TimeZone.getTimeZone("GMT");
Calendar toCal = new GregorianCalendar(gmtTZ);
toCal.setTimeInMillis(curCal.getTimeInMillis());
Date dd = toCal.getTime();
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a",Locale.US);
format.setTimeZone(gmtTZ);
String ff = format.format(dd);
java.sql.Timestamp curTimeInGMT = new java.sql.Timestamp(dateInLong(ff, "dd/MM/yyyy hh:mm:ss a"));
现在我正在使用getTime()
以上时间的毫秒值;在的getTime()方法,按照Java文档的
Long l = t.getTime();
定义是 Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.
所以,从我通过测试了这么多次了解,getTime()
将会给给定的时间和月份之间的毫秒差1,1970,00:00:00 GMT。
对于getTime()
与1970年1月1日00:00:00格林威治时间差异,它需要另一个GMT时间。 所以它需要将给定时间转换为GMT时间。对于该转换,它需要给定时间的时区。 它会考虑给定时间的时区为系统时区,它会得到相应的GMT时间,然后它会找到两个GMT时间之间的差异,它会返回差异。
我的理解是否正确?
显示的内容不是时间戳,而是时间戳的字符串表示形式......答案完全取决于您如何创建实际时间戳。 – assylias
为了理解,我只是复制了存储在表中的时间戳值以将其放在此处。 – Matchendran
什么表?在数据库表中?数据库列的类型是什么?等你需要提供更多的信息... – assylias