[英]Weird JAVA date formatting giving wrong result
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class HelloWorld{
public static void main(String []args){
String s = "Sep 01, 2014 6:30 pm";
SimpleDateFormat timeFormat = new SimpleDateFormat("MMM dd, YYYY hh:mm a", Locale.US);
try{
Date startTime = timeFormat.parse(s);
System.out.println(startTime);
}catch(Exception e){}
}
}
The result given is Sun Dec 29 18:30:00 CST 2013, which is totally wrong 给出的结果是CST 2013 Sun Dec 29 18:30:00,这是完全错误的
Please help!! 请帮忙!!
change 更改
SimpleDateFormat timeFormat = new SimpleDateFormat("MMM dd, YYYY hh:mm a", Locale.US);
to 至
SimpleDateFormat timeFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.US);
As Y stands for the Week year refer 作为Y代表本周年参考
A week year is in sync with a WEEK_OF_YEAR cycle. 一周的一周与WEEK_OF_YEAR周期保持同步。 All weeks between the first and last weeks (inclusive) have the same week year value.
第一个星期和最后一个星期(含)之间的所有星期都具有相同的星期年份值。 Therefore, the first and last days of a week year may have different calendar year values.
因此,一周的第一天和最后一天可能具有不同的日历年值。
More explanation on week year you can find here 有关周年的更多说明,请点击此处
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.