simpledateformat (android) 2018-10-03T09:00:36.845+0000 的这种日期格式是什么?

Which is this date format for simpledateformat (android) 2018-10-03T09:00:36.845+0000?

我收到响应字符串 2018-10-03T09:00:36.845+0000

我必须在几分钟前为 PrettyTime 解析它。

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

它不起作用,你能告诉我要在 SimpleDateFormat 中添加的 Dateformat 字符串吗?

这是我的代码

:

 try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
      long time = sdf.parse(device_for_bottomviews.get(i).lastupdate).getTime();
      PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
      String ago = prettyTime.format(new Date(time));
      lastupdate.setText(ago);
      } 
catch (Exception e)
{
      e.printStackTrace();
      lastupdate.setText(device_for_bottomviews.get(i).lastupdate);
}

我遇到异常

java.lang.IllegalArgumentException
        at java.util.Date.parse(Date.java:633)
        at java.util.Date.<init>(Date.java:272)
        at com.test.busmanagement.MapActivity$DeviceAdapter.getView(MapActivity.java:721)
        at android.widget.AbsListView.obtainView(AbsListView.java:2363)
        at android.widget.ListView.makeAndAddView(ListView.java:1970)
        at android.widget.ListView.fillDown(ListView.java:704)
        at android.widget.ListView.fillFromTop(ListView.java:765)

您可以将此格式用作模式

yyyy-MM-dd'T'HH:mm:ss.SSSX

您不需要引用日期格式字符串的 'zone' 部分,这里是更正后的版本:

"yyyy-MM-dd'T'HH:mm:ss.SSSZ"