Java date Calendar class get month and hour

Source: Internet
Author: User
package com.ecode.li.date;   import java.io.filenotfoundexception; import  java.io.fileoutputstream; import java.io.ioexception;  import java.io.objectoutputstream;  import java.util.Calendar; import java.util.Date;  import  java.util.gregoriancalendar;   public class calendartest {  /**   
 * calendar class use    *    *  @param    */ 
 public static void main (String[] args)  {   //  instantiation     calendar cale = calendar.getinstance ();   if  (cale 
Instanceof gregoriancalendar)  {    system.out.println ("This shows the creation of a GregorianCalendar class object, and the class is a subclass of the calendar abstract class     ");   }    //  from a   Get  Date  object in calendar  object    dAte date = cale.gettime ();   /*     *  will  Date  Object reacts to a  Calendar  object, calendar/gregoriancalendar  no constructors can accept     *  date  object   So we need to get an instance first and then set  Date  object     */    cale.settime (date);   //  Current year     int year = cale.get (calendar.year);    SYSTEM.OUT.PRINTLN (year);     //  current month  calendar.month starting from 0      int month =  (Cale.get (calendar.month))  + 1;   system.out.println
(month);     //  days of the current month: that is, the current day    int day_of_month =  Cale.get (calendar.day_of_month);        // Calendar.DAY_OF_MONTH  and   calendar.date  is equivalent to     int dates = cale.get (calendar.date);    System.oUT.PRINTLN (dates);    system.out.println (day_of_month);     //  Current time: HOUR_ Of_day-24-hour     int hour24 = cale.get (calendar.hour_of_day);    //  HOUR-12-hour     int hour12 = cale.get (calendar.hour);    System.out.println (HOUR24);    system.out.println (hour12);     //  current Score
    int minute = cale.get (Calendar.minute);   //  Current SEC     int second = cale.get (Calendar.second);    system.out.println (minute) ;    system.out.println (second);     //  week  calendar.day_of_ Week Digital (1~7) (Sunday ~ Saturday)         int day_of_week =  Cale.get (calendar.day_of _week)  - 1;   system.out.println (day_of_week);     //  first weeks of the current year    int week_of_year =  Cale.get (calendar.week_of_year);    system.out.println ( Week_of_year);     // //The number of weeks in the current month    // int week_of_month =  cale.get (calendar.week_of_month);   //         //  //the first few weeks of the current month     // int day_of_week_in_month = cale.get (Calendar.DAY_OF _week_in_month);   //         // //The first days of the current year  
   // int day_of_year = cale.get (calendar.day_of_year);  } } 


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.