这究竟是什么&QUOT时间格式,日期和QUOT;:"二〇一四年八月二十○日00:00:00 -0500"? [英] What is the Time format for this "date": "2014-08-20 00:00:00 -0500"?

查看:315
本文介绍了这究竟是什么&QUOT时间格式,日期和QUOT;:"二〇一四年八月二十○日00:00:00 -0500"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将这个日期的方式如下:

 的SimpleDateFormat fromFormat =新的SimpleDateFormat(YYYY-MM-DD HH:MM:SS SSSZ);
 

但我得到了:

  java.text.ParseException:无法解析的日期:2014年9月20日00:00:00 -0500(偏移量20)
 

解决方案

这是-0500是UTC的偏移量,在RFC822格式。你只是想以Z ,没有 SSS

借助的Andr​​oid 的SimpleDateFormat 文档有像这样的表:

  • 符号:Z
  • 含义:时区(RFC 822)
  • 类:(时区)
  • 示例: Z / ZZ / ZZZ : - 0800 ZZZZ :格林尼治标准​​时间08:00 ZZZZZ : - 08:00

我也亲自指定一个区域,作为理所当然的事:这是一个机器可读的格式,而不是一个人性化的格式,所以我通常会指定 Locale.US

  SimpleDateFormat的格式=新的SimpleDateFormat(YYYY-MM-DD HH:MM:SS Z,
                                                Locale.US);
字符串文本=2014年8月20号00:00:00 -0500;
的System.out.println(format.parse(文本));
 

I tried converting this date the following way:

SimpleDateFormat fromFormat  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSSZ");

but I got:

 java.text.ParseException: Unparseable date: "2014-09-20 00:00:00 -0500" (at offset 20)

解决方案

That "-0500" is the offset from UTC, in RFC822 format. You just want Z, without the SSS.

The Android SimpleDateFormat docs have it like this in the table:

  • Symbol: Z
  • Meaning: time zone (RFC 822)
  • Kind: (Time Zone)
  • Example: Z/ZZ/ZZZ:-0800 ZZZZ:GMT-08:00 ZZZZZ:-08:00

I would also personally specify a locale, as a matter of course: this is a machine-readable format rather than a human-oriented format, so I'd usually specify Locale.US:

SimpleDateFormat format  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z",
                                                Locale.US);
String text = "2014-08-20 00:00:00 -0500";
System.out.println(format.parse(text));

这篇关于这究竟是什么&QUOT时间格式,日期和QUOT;:"二〇一四年八月二十○日00:00:00 -0500"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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