Calendar时间获取明细

/**
 * Copyright (c) 2011 Noah
 * All right reserved.
 */
package com.noah.ebusiness.services;

import java.util.*;

/**
 * 类描述
 * @author zhaoxuan
 * @create_time 2013-2-4 上午10:46:45
 * @project test
 */
public class test {

  /**
   * @param args
   */
  public static void main(String[] args) {
    Calendar calendar = new GregorianCalendar();  
    Date trialTime = new Date();  
    calendar.setTime(trialTime);  
    // print out a bunch of interesting things  
    System.out.println("ERA: " + calendar.get(Calendar.ERA));  
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));  
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));  
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));  
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));  
    System.out.println("DATE: " + calendar.get(Calendar.DATE));  
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));  
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));  
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));  
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));  
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));  
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));  
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));  
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));  
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));  
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));  
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));  
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));  
    System.out.println("Current Time, with hour reset to 3");  
    calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override  
    calendar.set(Calendar.HOUR, 3);  
    System.out.println("ERA: " + calendar.get(Calendar.ERA));  
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));  
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));  
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));  
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));  
    System.out.println("DATE: " + calendar.get(Calendar.DATE));  
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));  
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));  
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));  
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));  
    
    /** 结果:
     *  ERA: 1
        YEAR: 2013
        MONTH: 1
        WEEK_OF_YEAR: 6
        WEEK_OF_MONTH: 2
        DATE: 4
        DAY_OF_MONTH: 4
        DAY_OF_YEAR: 35
        DAY_OF_WEEK: 2
        DAY_OF_WEEK_IN_MONTH: 1
        AM_PM: 0
        HOUR: 10
        HOUR_OF_DAY: 10
        MINUTE: 49
        SECOND: 21
        MILLISECOND: 890
        ZONE_OFFSET: 8
        DST_OFFSET: 0
        Current Time, with hour reset to 3
        ERA: 1
        YEAR: 2013
        MONTH: 1
        WEEK_OF_YEAR: 6
        WEEK_OF_MONTH: 2
        DATE: 4
        DAY_OF_MONTH: 4
        DAY_OF_YEAR: 35
        DAY_OF_WEEK: 2
        DAY_OF_WEEK_IN_MONTH: 1
     */

  }

}

 

posted @ 2013-02-04 14:33  残缘炫仔  阅读(330)  评论(0编辑  收藏  举报