首页 > 技术文章 > YYYY-MM-DD 与 yyyy-MM-dd 区别

mucheng 2017-01-04 14:52 原文

时间格式的问题:

String a = "2015-11-11 13:11:11";
System.out.println("The first one:");
Date date1 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").parse(a);
System.out.println(date1);
System.out.println("The second:");
Date date2 = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss").parse(a);
System.out.println(date2);
System.out.println("The third:");
Date date3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(a);
System.out.println(date3);

output:

The first one:
Sun Dec 28 13:11:11 CST 2014
The second:
Sun Jan 11 13:11:11 CST 2015
The second:
Wed Nov 11 13:11:11 CST 2015

注:

YYYY specifies the week of the year (ISO) while yyyy specifies the calendar year (Gregorian)

 

推荐阅读