Api--calendar

Source: Internet
Author: User

Java.util  
class Calendar

Public abstract class Calendar

Calendarclass is an abstract class that is aSpecific Momentswith a group such as Year,MONTH,Day_of_month,HOURwaitCalendar Fieldprovides a number of methods for converting betweenandfor the actionCalendar Field(for example, the date of next week) provides a number of methods. InstantavailableMillisecond Valueto indicate that it is a distance fromCalendar Element(that is, Greenwich Mean Time 1970 year 1 months 1 days of 00:00:00.000, Gregorian calendar) offset.

Calendar of the getinstance method returns a Calendar object whose Calendar field has been initialized by the current date and time:

Calendar RightNow = Calendar.getinstance ();

The month is represented by an integerfrom 0 to one,0 is a month,1 is February, and so on; 11 is December

Set

Public final void Set (int year, int month, int date)

set calendar field year , month   and day_of_month  . Keep the previous values for the other calendar fields. If you do not need to do this, call clear ()

Parameters:  

Year -Used to set Year the value of the Calendar field.

Month -Used to set MONTH the value of the Calendar field. The Month value is based on 0. For example, 0 represents January.

Date -Used to set Day_of_month the value of the Calendar field.

Get

public int Get (int field)

returns the value of the given Calendar field. In lenient mode, all calendar fields are normalized. In non-lenient mode, all calendar fields are validated, and if any calendar fields have out-of-range values, this method throws an exception. Normalization and validation are handled through the complete () method, which is related to the calendar system.

Parameters:  

Field -the given calendar field.

return:  

The value of the given Calendar field.

Thrown:  

arrayindexoutofboundsexception -If the specified field is out of range (field < 0 | | field >= field_count).

package cn.itcast.p3.calendar; import java.util.calendar; public class  Calendardemo {    public static void main (String[] args)  {              /*          *  Demo Calendar. Calendar        calendar c = calendar.getinstance ();         // system.out.println (c);                   /*  java.util.gregoriancalendar[time=1364193332890,arefieldsset=true,          * areallfieldsset=true,lenient=true,         *  zone=sun.util.calendar.zoneinfo[id= "Asia/shanghai",offset=28800000,          * dstsavings=0,usedaylight=false,transitions=19,lastrule=null],          * firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,          * YEAR=2013,MONTH=2,WEEK_OF_YEAR=13,WEEK_OF_MONTH=5,          * DAY_OF_MONTH=25,DAY_OF_YEAR=84,DAY_OF_WEEK=2,          * DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=2,                  *HOUR_OF_DAY=14,MINUTE=35,          * SECOND=32,MILLISECOND=890,ZONE_OFFSET=28800000,DST_OFFSET=0]          */                  // show (c);                           //  set a date for a specific day.         // c.set (2012,3, 5);         // c.add (calendar.month, -9);                  //  Exercise: How many days in February of a year.         int year = 2013;         c.set (year, 2, 1);         c.add ( CALENDAR.DAY_OF_MONTH,&NBSP;-1);         show (c);                  }                  public static void  show (calendar c)  {                      int year = c.get ( Calendar.year);             int month =  c.get (Calendar.month)  + 1;             int day = c.get (Calendar.day_of_month);             int week = c.get (Calendar.day_of_week);             string str_week = getweek (week);                       &NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (year +  "year"  + month +  "month"  +  day +  "Day Week"  + str_week);        }         &nbSp;        private static string getweek (Int num)  {        String[] weeks = {  "",  "Day",   "One",  "two",  "three",  "four",  "five",  "six"  };                  return weeks[num];    }}

Api--calendar

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.