The Calendar class for Java classes

Source: Internet
Author: User

Package com;import java.util.calendar;/** * calendar class overview and methods  *  Calendar class Overview: The Calendar class is an abstract class that provides methods for converting between specific moments and a set of calendar fields, such as yeae, month,, * , and provides methods for manipulating calendar FIELDS.  *  *  member Method:  * public static calendar getinstance ()  *  Public int get (int field)   Returns the value of the given calendar field, the amount of the Calendar class each field is a static member variable, and is an int type  * public  Void add (int field,int amount)  * public final void set (int year, Int month,int date)  */public class calendardemo {public static void  main (string[] args)  {calendar calendar = calendar.getinstance ();//get year int  Year = calendar.get (calendar.year); System.out.println ("year:" +year);//year: 2016//get month Int month = calendar.get (calendar.month); System.out.println ("month:" + (month+1));//month: 10//acquisition Day Int day = calendar.get (calendar.day_of_month); System.out.println ("Day: "+day);//day: 12}} 
Package com;import java.util.calendar;/** * calendar class overview and methods  *  Calendar class Overview: The Calendar class is an abstract class that provides methods for converting between specific moments and a set of calendar fields, such as yeae, month,, * , and provides methods for manipulating calendar FIELDS.  *  *  member Method:  * public static calendar getinstance ()  *  Public int get (int field)   Returns the value of the given calendar field, the amount of the Calendar class each field is a static member variable, and is an int type  * public  Void add (int field,int amount)   Work with the current calendar based on the given calendar field and the appropriate time  * public final  void set (int year,int month,int date)   Set the month and day of the current current calendar   */public  Class calendardemo {public static void main (string[] args)  {// Gets the current calendar time calendar calendar = calendar.getinstance (); Int year = calendar.get ( calendar.year); int month = calendar.get (calendar.month); Int date = calendar.get ( calendar.date); System.out.println ("the time of the current period is:" +year+ "-" + (month+1) + "-" +dAte);//the time of the period is: 2016-10-12//three years ago today Calendar.add (calendar.year, -3); Year = calendar.get ( calendar.year); month = calendar.get (calendar.month);d ate = calendar.get (Calendar.DATE); System.out.println ("3 years ago today:" +year+ "-" + (month+1) + "-" +date ")//3 years ago Today: 2013-10-12//three years later today Calendar.add ( calendar.year, 3); year = calendar.get (calendar.year); Month = calendar.get ( Calendar.month);d Ate = calendar.get (calendar.date); System.out.println ("three years after today:" +year+ "-" + (month+1) + "-" +date);//three years later today: 2016-10-12, this is because just set 3 years Ago//set date Calendar.set ( 2019, 11, 11); year = calendar.get (calendar.year); Month = calendar.get ( Calendar.month);d Ate = calendar.get (calendar.date); System.out.println ("the time after setting is:" +year+ "-" + (month+1) + "-" +date);//after Setting the Time: 2019-12-11}}


This article is from the "11831428" blog, please be sure to keep this source http://11841428.blog.51cto.com/11831428/1861258

The Calendar class for Java classes

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.