在java中解析带时区的时间戳? [英] Parsing timestamp with timezone in java?
本文介绍了在java中解析带时区的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用从DB获取的时区解析一串格式时间戳。字符串如下:
I'm trying to parse a string of format timestamp with timezone obtained from a DB. The String is as follows :
SimpleDateFormat mdyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSZ");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date d1 = mdyFormat.parse("2014-04-01 15:19:49.31146+05:30");
String mdx = sdf.format(d1);
System.out.println(mdx);
问题是,我收到错误消息:
Problem is, I get an error saying :
Exception in thread "main" java.text.ParseException: Unparseable date: "2014-04-01 15:19:49.31146+05:30"
at java.text.DateFormat.parse(DateFormat.java:357)
at com.karthik.Timestampvalidate.main(Timestampvalidate.java:31)
有谁知道如何解决这个问题?
Does anyone know how to fix this ?
推荐答案
您需要使用 X
而不是 Z
:
SimpleDateFormat mdyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSX");
参见 javadoc 了解更多信息。
注意:仅适用于Java 7+ 。
Note: only available in Java 7+.
这篇关于在java中解析带时区的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文