Java - 将CET字符串转换为Date [英] Java - convert CET string to Date

查看:123
本文介绍了Java - 将CET字符串转换为Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此字符串转换为日期:

I'm trying to convert this String to Date:

Tue Mar 01 11:46:32 CET 2016

Tue Mar 01 11:46:32 CET 2016

这是我的代码:

DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date mTimeStamp = format.parse(getTimeStamp());

它抛出一个ParseExeption ...

it throws a ParseExeption...

推荐答案

您的格式很好 - 您的问题可能是您的默认语言环境不是英语,日期和/或月份名称在您的默认语言中无效。

Your format is fine - your issue may be that your default locale is not English and the day and/or month names are not valid in your default language.

这应该按预期工作:

DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date mTimeStamp = format.parse("Tue Mar 01 11:46:32 CET 2016");

这篇关于Java - 将CET字符串转换为Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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