【发布时间】:2012-08-12 15:03:43
【问题描述】:
我正在尝试将 Json 日期字符串转换为 java 日期格式。但是,当涉及到“return df.parse(tarih)”行时,它会出错。
JSON:
{"DateFrom":"\/Date(1323087840000+0200)\/"}
Java 代码:
private Date JSONTarihConvert(String tarih) throws ParseException
{
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssz" );
if ( tarih.endsWith( "Z" ) ) {
tarih = tarih.substring( 0, tarih.length() - 1) + "GMT-00:00";
} else {
int inset = 6;
String s0 = tarih.substring( 6, tarih.length()-1 - inset );
String s1 = tarih.substring( tarih.length()- inset,tarih.length()-2 );
tarih = s0 + "GMT" + s1;
}
return df.parse( tarih );
}
当我调用这个方法时,tarih参数是:/Date(1323087840000+0200)/
【问题讨论】:
-
究竟是什么错误,您能否也发布一个 tarih 的示例? :)
-
提供的日期没有
-。然后,您也可以在没有-的情况下将该字符串转换为其他内容。然后您的日期格式无法正确解析它,因为它需要-。 -
Tarih 是来自土耳其语的日期,基本上 tarih 是他试图解析的 JSON 日期。