【发布时间】:2010-11-30 09:33:02
【问题描述】:
2010-06-14 02:21:49-0400 或 2010-06-14 02:21:49+0400
以上是来自我的网络服务的字符串... 有没有办法根据本地机器时区将此字符串转换为日期
我使用了 Simpledateformatter .. 但无法正确显示.. 请帮助
【问题讨论】:
2010-06-14 02:21:49-0400 或 2010-06-14 02:21:49+0400
以上是来自我的网络服务的字符串... 有没有办法根据本地机器时区将此字符串转换为日期
我使用了 Simpledateformatter .. 但无法正确显示.. 请帮助
【问题讨论】:
使用java.text.SimpleDateFormat 进行日期格式化(从日期字符串到日期对象)。模式将是yyyy-MM-dd HH:mm:ssZ
例子:
String dateStr = "2010-06-14 02:21:49-0400";
String pattern = "yyyy-MM-dd HH:mm:ssZ";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date date = sdf.parse(dateStr);
PS要使用TimeZone,您可以使用TimeZone.getDefault()并将其添加到SimpleDateFormat。
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setTimeZone(TimeZone.getDefault());
Date date = sdf.parse(dateStr);
【讨论】:
is there a way to convert this string to the date according to the local machine time zone)。您能否进一步更新您的问题,以便我们确切知道您想要什么?