【问题标题】:How to change milliseconds to "yyyy-MM-dd'T'HH:mm:ssS" format? [duplicate]如何将毫秒更改为“yyyy-MM-dd'T'HH:mm:ssS”格式? [复制]
【发布时间】:2013-05-24 12:43:47
【问题描述】:

我从 JSON 获取以毫秒为单位的时间(“1369807669”)格式,我必须将其更改为“yyyy-MM-dd'T'HH:mm:ssS”格式......我该怎么做?

我使用了这段代码,但我得到的时间不是实际时间。

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
DateTime = df.format(millis);

但我得到的时间是“1970-12-23'T'12:54:32+0000”,这是错误的......

我应该得到类似“2013-05-29'T'12:06:53+0000”这样的时间

【问题讨论】:

    标签: android time format simpledateformat


    【解决方案1】:

    检查您当前的日期并检查您的 json 毫秒数

    SimpleDateFormat formatter = new SimpleDateFormat(
                    "yyyy-MM-dd'T'HH:mm:ssZ");
    
              df.setTimeZone(TimeZone.getTimeZone("GMT"));
            String currentDate = formatter.format(new Date(System
                    .currentTimeMillis())));
    

    可能是你在 json 中弄错了时间

    【讨论】:

      【解决方案2】:

      你有seconds 而不是milliseconds 你应该增加你的秒数* 1000

      【讨论】:

      • 糟糕!我的错...尽管感谢您的帮助...
      猜你喜欢
      • 2017-11-14
      • 2018-03-25
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多