Calendar gets the current time before

Source: Internet
Author: User

@Test      Public void Test () {            /// because the calendar's construction method is private, instantiate a calendar object with the GetInstance method        Calendar Calendar = calendar.getinstance ();                 -1);    // get the        day before        Date date = calendar.gettime ();                 New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");            System.out.println (Df.format (date));            }

This is a very good example, easy to understand, can help us to easily grasp the calendar of the use of methods. Can watch the source code, the underlying use of the map collection to achieve

 PublicMap<string, Integer> getdisplaynames (intFieldintstyle, locale locale) {        if(!checkdisplaynameparams (field, style, All_styles, LONG, Locale, Era_mask| month_mask| day_of_week_mask|am_pm_mask)) {            return NULL; }        //All_styles        if(style = =all_styles) {Map<String,Integer> Shortnames =Getdisplaynamesimpl (field, short, locale); if(field = = ERA | | field = =am_pm) {                returnShortnames; } Map<String,Integer> Longnames =getdisplaynamesimpl (field, LONG, locale); if(Shortnames = =NULL) {                returnLongnames; }            if(Longnames! =NULL) {shortnames.putall (longnames); }            returnShortnames; }        //Short or LONG        returngetdisplaynamesimpl (field, style, locale); }    PrivateMap<string,integer> Getdisplaynamesimpl (intFieldintstyle, locale locale) {DateFormatSymbols symbols=dateformatsymbols.getinstance (locale); String[] Strings=getfieldstrings (field, style, symbols); if(Strings! =NULL) {Map<String,Integer> names =NewHashmap<string,integer>();  for(inti = 0; i < strings.length; i++) {                if(strings[i].length () = = 0) {                    Continue;            } names.put (Strings[i], i); }            returnnames; }        return NULL; }

Calendar gets the current time before

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.