Differences in YYYY (uppercase) and yyyy (lowercase) When Java time is formatted

Source: Internet
Author: User
Tags dateformat

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.