【问题标题】:Convert GMT time to Local time using Java [closed]使用 Java 将 GMT 时间转换为本地时间 [关闭]
【发布时间】:2016-07-11 23:08:53
【问题描述】:

我有Thu Mar 24 13:00:00 GMT+07:00 2016

我想把它转换成Thu Mar 24 22:00:00 pm。如何使用SimpleDateFormat 做到这一点?

【问题讨论】:

  • 欢迎来到 Stack Overflow。到目前为止,您尝试过什么吗?如果您使用的是 SimpleDateFormat,则表明您有一些代码 - 请展示您所拥有的,以及到目前为止的结果。

标签: java android string date parsing


【解决方案1】:

你应该首先解析文本输入:

    Date date = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ENGLISH)
            .parse("Thu Mar 24 13:00:00 GMT+07:00 2016");

然后以新格式格式化为当地时间

    String str = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", Locale.ENGLISH).format(date);

【讨论】:

    【解决方案2】:

    看看这个page然后试试这个:

    SimpleDateFormat dateFormat = new SimpleDateFormat("E MMM d hh:mm:ss aa");
    String formattedDate = dateFormat.format(new Date());
    System.out.println(formattedDate);
    
    • E 代表一天
    • MMM 代表缩短的月份
    • d 代表当天的数字
    • hh:mm:ss 是经典的时间格式
    • a 是上午/下午标记

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2013-10-29
      • 2010-09-15
      • 2012-08-28
      • 2012-05-30
      相关资源
      最近更新 更多