- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将字符串转换为日期,但我还没有得到它。
我的字符串格式为:
"Fri Jun 13 10:24:01 BRT 2014"
我在 Google 上搜索并找到了此解决方案,但仍然继续捕获异常。
这是我的代码:
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("EEE MMM dd HH:mm:ss 'BRT' yyyy", Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("BRT"));
try {
return df.parse(dateString);
} catch (Exception e) {
return null;
}
最佳答案
您需要:
SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("BRT"));
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Date d = df.parse("Fri Jun 13 10:24:01 BRT 2014");
System.out.println(utcFormat.format(d)); // output: 2014-06-13T12:24:01+0200
考虑以下更正:
Locale.ENGLISH
而不是 Locale.getDefault()
可以可靠地解析“Jun”或“Fri”等英文名称
使用模式符号 z 而不是文字“BRT”,否则解析器无法将字符串“BRT”解释为时区名称的缩写,该时区名称被解释为巴西标准时间(巴西标准时间)您的情况只是解析为文字,因此没有考虑 UTC-03:00 的时区偏移。
关于java - 将字符串转换为日期 BRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24213324/
我正在尝试将字符串转换为日期,但我还没有得到它。 我的字符串格式为: "Fri Jun 13 10:24:01 BRT 2014" 我在 Google 上搜索并找到了此解决方案,但仍然继续捕获异常。
我在不同的时区有不同的字符串: 2019-11-13 00:52:03 ADT 2019-11-13 00:52:03 欧洲东部时间 2019-11-13 00:52:03 BRT 我使用格式 Y-m
我已经为我的应用程序创建了一个登录屏幕,并且选择了用户名和密码。当我写了错误的信息时,它可以工作,但正确的信息不起作用,请帮忙。这是我的登录按钮。 @IBAction func loginButto
(之前发过here,发错子了,信息不足,已关闭,我编辑了,编辑好像被删除了,帖子归于炼狱,所以抱歉重新发,我不知道之前的帖子是否可以/应该复活) 在 R 中,我使用 dismo 运行了一些 Boost
某些国家/地区不会缩短时区。 对于印度来说,缩写是 IST 没问题,但对于巴西等其他国家,我得到的不是 BRT,而是 -30 var rightNow = new Date(); alert(Stri
我有一个使用 SimpleDateFormat 的代码: String data = jTData.getText(); DateFormat formatter = new SimpleDateFo
我是一名优秀的程序员,十分优秀!