我正在开发一个代号项目,并且正在努力将设备时间转换为 UTC。 我使用这段代码:
Calendar cal = Calendar.getInstance();
System.out.println(cal.getTimeZone());
TimeZone tzUTC = TimeZone.getTimeZone("UTC");
com.codename1.l10n.DateFormat dtfmt = new com.codename1.l10n.SimpleDateFormat("EEE, yyyy-MM-dd KK:mm a z");
dtfmt.setTimeZone(tzUTC);
System.out.println("UTC: " + dtfmt.format(cal.getTime()));
并且代号一拒绝 setTImeZone
方法。
我使用java.text.DateFormat
,但是当我运行它时,condename也无法编译它。
最佳答案
它可能无法真正回答您真正的问题,但以下内容对我有用:
Calendar cal = Calendar.getInstance();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
TimeZone tzUtc = TimeZone.getTimeZone("UTC");
df.setTimeZone(tzUtc);
System.out.println("UTC: " + df.format(cal.getTime()));
我不知道com.codename1.l10n.DateFormat
,因此很抱歉无法为您提供帮助。
关于java - codenameone 将时间转换为 utc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39360951/