用Java解析日期字符串 [英] Parse Date String in Java

查看:318
本文介绍了用Java解析日期字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期格式为"yyyy-MM-dd'T'HH:mm:ss.sssZ".例如,日期为"2018-07-17T09:59:51.312Z".我正在使用下面的代码来解析Java中的String.

I have date in the format "yyyy-MM-dd'T'HH:mm:ss.sssZ". for example the date is "2018-07-17T09:59:51.312Z". I am using the below code to parse the String in Java.

  String date="2018-07-17T09:59:51.312Z";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ");
   Date transactionDateTime = simpleDateFormat.parse(date);

这给了我无法解析的日期:"例外.谁能告诉我该怎么做?

This is giving me "Unparseable date:" Exception. Can anyone please tell me how to do this?

推荐答案

您忘记在Z - RFC 822 time zone (-0800)

String date = "2018-07-17T09:59:51.312Z";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Date transactionDateTime = simpleDateFormat.parse(date);

那样就可以了

这篇关于用Java解析日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆