Deep understanding of the set and get methods of calendar

Source: Internet
Author: User
Tags set time
/**
 * 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.

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.