关于时间DateFormat 很诡异的有关问题
关于时间DateFormat 很诡异的问题。
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.setTime(new Date());
Date sunday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String sundayStr = df.format(sunday);
return formatDate(sundayStr);
这段代码在windows下面跑一点问题没有返回当前时间。但是在linux下的tomcat里跑返回的时间居然是1970年。不管你传进去什么值都返回1970年。很奇怪。棕色的代码无非是转来转去没什么实际意思。但是在linux下却出了问题。
--------------------
因为采用了DateFormat.getDateInstance();,故使用系统默认构建时间方式。当linux使用LANG=EN是,所指定的格式化方式为西文,而程序在初始化DateFormat的时所使用的是中国本地格式所以异常。原来是这样啊。
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.setTime(new Date());
Date sunday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String sundayStr = df.format(sunday);
return formatDate(sundayStr);
这段代码在windows下面跑一点问题没有返回当前时间。但是在linux下的tomcat里跑返回的时间居然是1970年。不管你传进去什么值都返回1970年。很奇怪。棕色的代码无非是转来转去没什么实际意思。但是在linux下却出了问题。
--------------------
因为采用了DateFormat.getDateInstance();,故使用系统默认构建时间方式。当linux使用LANG=EN是,所指定的格式化方式为西文,而程序在初始化DateFormat的时所使用的是中国本地格式所以异常。原来是这样啊。
1 楼
大玉儿
2011-02-15
不知道这篇文章对你有没有帮助,你看看吧
http://it.newnew.cn/it64548.aspx
http://it.newnew.cn/it64548.aspx