java.util.Calendar的用法--java基础

文章作者 100test 发表时间 2007:11:14 12:48:55
来源 100Test.Com百考试题网


import java.util.*.

public class ShowDate {

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)).
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))). // in hours
System.out.println("DST_OFFSET: " (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))). // in hours
}

}

相关文章


“网络蚂蚁”的Java实现
J2me制作会动的波浪字体方法及代码
有状态网络的J2EE技术
彻底玩转手机Java游戏
java.util.Calendar的用法--java基础
J2ME游戏开发中如何使用层
ORM(Hibernate)方法基础学习
基于TCP多播的JGroup协议
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛