【问题标题】:TimeZone configurations时区配置
【发布时间】:2011-10-06 11:26:43
【问题描述】:

我在 SimpleDateFormat“Sun,2011 年 10 月 2 日 14:00:00 +0100”中收到此字符串,我的输出可以减少 1 小时吗?不是 +0100 而是 GMT?

谢谢

【问题讨论】:

  • 您想更改实际时间(即时间 = 时间 - 1 小时),还是只想以 GMT 时间打印时间?
  • 你能教我两种方法吗?谢谢

标签: android timezone


【解决方案1】:

休息一小时:

SimpleDateFormat sf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
sf.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
Calendar calendar = Calendar.getInstance(); 
Date now = calendar.getTime();

calendar.add(Calendar.HOUR,-1);
Date earlierTime = calendar.getTime();
System.out.println(sf.format(now)); // output: Thu, 06 Oct 2011 11:53:58 GMT
System.out.println(sf.format(earlierTime)); // output: Thu, 06 Oct 2011 10:53:58 GMT

【讨论】:

    猜你喜欢
    • 2021-06-09
    • 2011-12-19
    • 2023-03-11
    • 2013-08-15
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多