1

我想在 Android 应用程序中简单地显示不同国家和城市的时区。我正在创建一个天气更新应用程序,它需要国家的当地时间和显示天气的城市。谢谢

使用的代码:

DateFormat format = new SimpleDateFormat("MMMMM d, yyyy, h:mm a"); 
TimeZone utc = TimeZone.getTimeZone("America/New_York"); 
System.out.println(utc.getID()); 
GregorianCalendar gc = new GregorianCalendar(utc); 
Date now = gc.getTime(); 
System.out.println(format.format(now));
4

1 回答 1

0

您可以使用以下代码:

DateTime dt = new DateTime();

DateTime dtNewYork = dt.withZone(DateTimeZone.forID("America/New_York"))

或者对于时区,您可以使用

DateTimeZone zone = DateTimeZone.forID("Asia/Kolkata");

这是参考链接

于 2013-03-11T09:02:15.850 回答