SimpleDateFormat无法解析的日期如果区域设置为ES,则错误. Twitter"Created_At" [英] SimpleDateFormat Unparseable date Error if locale is ES. Twitter "Created_At"

查看:96
本文介绍了SimpleDateFormat无法解析的日期如果区域设置为ES,则错误. Twitter"Created_At"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将twitter"created_at"转换为阿根廷日期时间. 如果我这样做:

I'm trying to convert the twitter "created_at" to an Argentinian Date-time. If I do this:

final String TWITTER="EEE MMM dd HH:mm:ss";
        SimpleDateFormat sf = new SimpleDateFormat(TWITTER,new Locale("en"));  

它工作正常.

但是如果我更改为Locale("es")Locale("es","ES")Locale("es","AR"), 我收到此错误:

But if I change to Locale("es"), Locale("es","ES") or Locale("es","AR"), I am getting this error:

07-01 11:09:29.153:W/System.err(331):java.text.ParseException: 无法解析的日期:"2014年7月1日星期二13:57:36 +0000"

07-01 11:09:29.153: W/System.err(331): java.text.ParseException: Unparseable date: "Tue Jul 01 13:57:36 +0000 2014"

为什么我不能将日期转换为本地时间?

Why can't I convert the date to my local time?

根据Sotilios Delimanoris告诉我的有关使用两个SimpleDateFormat的信息,一个用于解析,另一个用于格式,我做到了:

Based on what Sotilios Delimanoris told me about using two SimpleDateFormat, one for parse and other for format, i've done this:

final String TWITTER="EEE MMM dd HH:mm:ss";  
SimpleDateFormat sf = new SimpleDateFormat(TWITTER,new Locale("en")); 
Date mystring = sf.parse(text); 
final String TWITTER2="dd-MM HH:mm:ss";  
SimpleDateFormat sf2 = new SimpleDateFormat(TWITTER2,new Locale("es","AR")); System.out.println(sf2.format(mystring)); 
return sf2.format(mystring); 

这是输出:

I/System.out(688):01-07 18:41:31

I/System.out(688): 01-07 18:41:31

一切正常,除了小时,它比实际显示的多了2个小时. –

Everything is ok, except for the hour, it's showing 2 hours more that what it should. –

我尝试过这样设置时区:

I have tried setting time zone like this:

sf2.setTimeZone(TimeZone.getTimeZone("UTC-3"));

现在更糟糕的是,它显示22:41:31

And now it's even worse, it shows 22:41:31

最后,它正在工作.不知道为什么,但是使用:

Finally, it's working. Don't know why, but using:

sf2.setTimeZone(TimeZone.getTimeZone("GMT-6"));

工作正常(仍然在阿根廷不是GMT-6)

Works fine (still in argentina is not GMT-6)

谢谢

推荐答案

您正在尝试使用我认为的西班牙语来解析日期字符串,但是TueJul并不是西班牙语中的短词.它们是英语单词的缩写.

You're trying to parse the date string in what I assume is Spanish, but Tue and Jul are not short words in Spanish. They are short for English words.

这篇关于SimpleDateFormat无法解析的日期如果区域设置为ES,则错误. Twitter"Created_At"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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