使用java.text.SimpleDateFormat解析日期字符串 [英] Parsing a date string using java.text.SimpleDateFormat
问题描述
1997-02-14T00:00:00.0000000 + 05:30
。日期字符串的奇怪的是时区信息。 +05:30
而不是通常的 +0530
。 我有基本的格式字符串准备好, yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ
这将是一个魅力,如果不是TZ信息。
任何人都可以提出解决这个问题的解决方案?有没有一些可以处理这种TZ信息的格式的字符串?
提前感谢
您是否可以使用正则表达式进行预处理,并替换时区,例如
String dateAndTime = 。
String preprocessed = dateAndTime.replace(([+ - ])(\\\\d):( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ 3);
//继续生活
I have a weird problem, I need to parse a date string that looks like 1997-02-14T00:00:00.0000000+05:30
. The odd thing about the date string is the time zone information. It's +05:30
instead of the usual +0530
.
I have the basic format string ready, yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ
which would have worked like a charm, if not for the TZ information.
Can anyone suggest a solution to this problem? Is there some kind format string which can handle that kind of TZ info?
Thanks in advance.
Can you not preprocess with a regex and replace the timezone e.g.
String dateAndTime = ...
String preprocessed = dateAndTime.replace("([+-])(\\d\\d):(\\d\\d)$", "$1$2$3");
// Go on with your life
这篇关于使用java.text.SimpleDateFormat解析日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!