Java Time Operations

Source: Internet
Author: User

Record some time common operations

 Public classDateca { Public Static voidMain (string[] args)throwsParseException {/**time operation the calendar Gregorian calendar **/Calendar CA=calendar.getinstance (); //get a single attribute for a date: year, month, week, day, time, minuteSystem.out.println (Ca.get (calendar.year)); System.out.println (Ca.get (Calendar.month));//get month starting from 0System.out.println (Ca.get (calendar.week_of_year));        System.out.println (Ca.get (calendar.day_of_month));        System.out.println (Ca.get (calendar.hour_of_day));        System.out.println (Ca.get (Calendar.minute)); //Date OperationCa.add (Calendar.year, 2);//two years back .System.out.println (Ca.get (calendar.year)); Ca.add (Calendar.month,2);//two months back .System.out.println (Ca.get (calendar.month)); Ca.add (Calendar.day_of_month,10);//two days back .System.out.println (Ca.get (calendar.day_of_month)); //set the required time directlyCa.set (calendar.year,100);//sets the given Calendar field to the given value. System.out.println (Ca.get (calendar.year)); Ca.set (2018, 7, 12);        System.out.println (Ca.get (calendar.year));        System.out.println (Ca.get (calendar.month));                System.out.println (Ca.get (calendar.day_of_month)); //Time Comparison recommendedSystem.out.println (Ca.after (NewDate ())); System.out.println (Ca.before (NewDate ())); //You can also get the time system for the specified time zoneSystem.out.println (Calendar.getinstance (locale.english)); /**Other Time operations **/        //current number of secondsSystem.out.println (System.currenttimemillis ()); System.out.println (NewDate (). GetTime ()); //Time FormattingSimpleDateFormat SF =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");        System.out.println (Sf.format (Ca.gettime ())); System.out.println (Sf.parse ("2018-10-12 09:18:23"). After (NewDate ())); }}

Java Time Operations

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.