In Java, most of the time format dates are SimpleDateFormat, such as a date format "yyyy-MM-dd"
.
It is important to note that for years, uppercase Y and lowercase y have different meanings.
Y is year, y means week year.
After testing, the results are as follows: Week year means that the week in which the day is located, the week begins in Sunday and ends in Saturday, so long as this week spans the year.
PackageTime ;ImportJava.text.DateFormat;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;/*** Created by sheting on 10/20/2017*/ Public classTest { Public Static voidMain (string[] args) {Calendar Calendar=calendar.getinstance (); //2014-12-31Calendar.set (Calendar.december, 31); Date strDate1=Calendar.gettime (); //2015-01-01Calendar.set, Calendar.january, 1); Date StrDate2=Calendar.gettime (); //uppercase yyyyDateFormat formatuppercase =NewSimpleDateFormat ("Yyyy/mm/dd"); System.out.println ("2014-12-31 to Yyyy/mm/dd:" + Formatuppercase.format (strDate1));//2014-12-31 to Yyyy/mm/dd:2015/12/31System.out.println ("2015-01-01 to Yyyy/mm/dd:" + Formatuppercase.format (strDate2));//2015-01-01 to Yyyy/mm/dd:2015/01/01//lowercase yyyyDateFormat formatlowercase =NewSimpleDateFormat ("Yyyy/mm/dd"); System.out.println ("2014-12-31 to Yyyy/mm/dd:" + Formatlowercase.format (strDate1));//2014-12-31 to Yyyy/mm/dd:2014/12/31System.out.println ("2015-01-01 to Yyyy/mm/dd:" + Formatlowercase.format (strDate2));//2015-01-01 to Yyyy/mm/dd:2015/01/01 }}
Differences in YYYY (uppercase) and yyyy (lowercase) When Java time is formatted