gpt4 book ai didi

Java : Get the time of different timezone

转载 作者:太空狗 更新时间:2023-10-29 16:16:13 27 4
gpt4 key购买 nike

我目前正在为我的一个应用程序开发一个同步模块。我正在根据 LastUpdated 时间同步本地和服务器之间的记录,这不过是一个时间戳。服务器在新加坡,那么如何在我的 Android 应用程序中将时区设置为新加坡?

我试过了,

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ENGLISH);
sdf.setTimeZone(TimeZone.getTimeZone("VST") );

和,

Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("Asia/Singapore"));
System.out.println(calendar.get(Calendar.HOUR_OF_DAY));

仍然没有运气。

或者有什么方法可以为本地和服务器设置通用时区?服务器端语言是 ASP.Net

最佳答案

您的 SimpleDateFormat 示例几乎是正确的。我相信您想要新加坡的 SGT 并且您需要调用 DateFormat.format(Date) .您还可以将 TimeZone 传递给 Calendar.getInstace(TimeZone)喜欢

TimeZone tz = TimeZone.getTimeZone("SGT");
sdf.setTimeZone(tz);
System.out.println(sdf.format(Calendar.getInstance().getTime()));
System.out.println(Calendar.getInstance(tz));

关于Java : Get the time of different timezone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622844/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com