简体   繁体   English

如何在Java中的本地/任何时区中找到从时间戳经过的毫秒数

[英]How to find number of milliseconds that have elapsed from a timestamp in local/any timezone in java

I know that System.currentTimeMillis() gives the number of milliseconds that have elapsed from epoch(1 Jan 1970, 00:00:00 GMT). 我知道System.currentTimeMillis()给出了从纪元(1970年1月1日,格林尼治标准时间00:00:00)过去的毫秒数。 But I need a solution to find the number of milliseconds that have elapsed from say 1 Jan 1970, 00:00:00 IST or any other timezone in general. 但是,我需要一个解决方案来查找从1970年1月1日IST 00:00:00 IST或一般任何其他时区过去的毫秒数。

Convert the Calendar to the IST timezone and compare the values by calling Calendar.getTimeInMillis(); Calendar转换为IST时区,并通过调用Calendar.getTimeInMillis();比较值Calendar.getTimeInMillis();

Please go through the below link for converting to TimeZones. 请通过以下链接转换为TimeZones。 TimeZone Conversion 时区转换

This is a way to get the time for a specific zone: 这是一种获取特定区域时间的方法:

DateTimeZone tz = DateTimeZone.forID("America/Winnipeg");
DateTime dt = new DateTime(tz);
DateFormat df = DateFormat.getDateInstance();
df.format(dt.getTime());

The IDs can be found on this site . 可以在此站点上找到这些ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM