/**
* Calendar provides a set method
* You can set a time component with a given value
* Time component using a number of constants provided by Calendar
* @author huawangxin
*
*/
public class Calendardemo {public
static void Main (String args[]) {
Calendar calendar=calendar.getinstance (); c2/>/*
* 2008-08-08 20:22:35 * If the value of the
set time unit will affect the value that is not set,
* Then the value will also correspond to the change is like,
* We set the date of the month, then the corresponding weeks will follow the change.
* *
Calendar.set (calendar.year, 2014);
Calendar.set (calendar.month,10);
* * * month is starting from 0, 0 for January
* day_of_month usually said "number"
* day_of_year usually said the first days
* Day_of_weer Usually say the week
// Calendar.set (calendar.am_pm); Calendar.set (Calendar.hour, 8);
Calendar.set (calendar.day_of_month,25);
Calendar.set (Calendar.hour_of_day, one);
*
* * The calendar will automatically carry * when the set unit value exceeds the maximum allowable value of the unit * The
hour will be put to the Sky
* Set week will also affect the
date
*
* * * Calendar.set (Calendar.minute, one);
Calendar.set (Calendar.second, one);
1 indicates Sunday, 2 indicates Monday
calendar.set (Calendar.day_of_week, 1);
Date date=calendar.gettime ();
SYSTEM.OUT.PRINTLN (date);
}
/**
* Calendar's Get method
* Can obtain the value of one time unit in the time represented by the current time calendar
* @author wangxin
*
/Public Class CalendarDemo2 {public
static void main (String []args) {
Calendar calendar=calendar.getinstance ();
Gets which year
int year=calendar.get (calendar.year);
int Mouth=calendar.get (calendar.month) +1;
*
* * Day_of_month
* DATE is the same as the Day_of_month function *
/int day=calendar.get (calendar.day_of_month);
int Hour=calendar.get (calendar.hour);
int Minute=calendar.get (calendar.minute);
int Second=calendar.get (calendar.second);
int Week=calendar.get (calendar.day_of_week);
System.out.println ("Zhou" + (week==1?7:week-1));
System.out.println (year+ "-" +mouth+ "-" +day);
System.out.println (hour+ ":" +minute+ ":" +second);
}
If there are any wrong or additional places, please criticize and advise, thank you.