【问题标题】:Get users timezone converted to my timezone on Android [duplicate]在Android上将用户时区转换为我的时区[重复]
【发布时间】:2018-06-14 07:03:57
【问题描述】:

我正在制作一个实时跟踪应用程序。我添加了一些位于 2 个不同时区的用户。我正在尝试获取他们最后一次在线的时间和日期,到目前为止,我已经能够获取日期和时间,但是,它向我显示了他们国家/地区的在线时间,我想根据我的时区。

【问题讨论】:

标签: android datetime geolocation android-gps


【解决方案1】:

您需要知道他们上次更新时间是哪个 GMT 时间,然后将其转换为您的 GMT 时间。但是,如果您让用户在您的 GMT 中更新他们的本地时间,它会更简单。

public void timeZoneConverter() {

 //Date will return local time in 

 Date localTime = new Date(); 

 //creating DateFormat for converting time from local timezone to GMT

 DateFormat converter = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");

 //getting GMT timezone, you can get any timezone e.g. UTC

 converter.setTimeZone(TimeZone.getTimeZone("GMT"));

 System.out.println("Local time : " + localTime);;
 System.out.println("Time in GMT : " + converter.format(localTime));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-07
    • 2015-08-11
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2011-08-13
    • 1970-01-01
    相关资源
    最近更新 更多