Date result1 = string2Date("2016-12-15", "yyyy-MM-dd");
System.out.println(result1);
Date result2 = string2Date("2016-12-15", "YYYY-MM-DD");
System.out.println(result2);
Date date1 = new Date();
System.out.println(date2String(date1, "yyyy-MM-dd"));
System.out.println(date2String(date1, "YYYY-MM-DD"));
Thu Dec 15 00:00:00 CST 2016
Sun Dec 27 00:00:00 CST 2015
2016-12-20
2016-12-355
第一种情况下,明明是2016年的日期,转完格式变成了2015年。。。我去
试验版本jdk1.7,我看有些文章说,y是year,Y是week year,比如:
yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar.
意思就是YYYY格式的话,如果一月1日是星期一,星期二,星期三或星期四,它是在01周。如果一月1日是星期五,星期六或星期日,它在前一年的52周或53周。
这和我试验的结果不符,2016年的12月份,再怎么算week也不能算到2015年去吧,
我暂时还没查明白java中这部分到底怎么实现的,感觉可能和windows操作系统有关系?
开发中还是用yyyy-MM-dd来做日期格式化,其它的就不要用了。