……天天向上

好的想法总是无穷无尽

统计

留言簿(1)

阅读排行榜

评论排行榜

calendar获取当前日期及时间的用例

  1. import Java.util.*;
  2.   public class ShowDate {
  3.   public static void main(String[] args) {
  4.   Calendar calendar = new GregorianCalendar();
  5.   Date trialTime = new Date();
  6.   calendar.setTime(trialTime);
  7.   // print out a bunch of interesting things
  8.   System.out.println("ERA: " + calendar.get(Calendar.ERA));
  9.   System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
  10.   System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
  11.   System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
  12.   System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
  13.   System.out.println("DATE: " + calendar.get(Calendar.DATE));
  14.   System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
  15.   System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
  16.   System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
  17.   System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
  18.   System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
  19.   System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
  20.   System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
  21.   System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
  22.   System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
  23.   System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
  24.   System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
  25.   System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));
  26.   System.out.println("Current Time, with hour reset to 3");
  27.   calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
  28.   calendar.set(Calendar.HOUR, 3);
  29.   System.out.println("ERA: " + calendar.get(Calendar.ERA));
  30.   System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
  31.   System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
  32.   System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
  33.   System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
  34.   System.out.println("DATE: " + calendar.get(Calendar.DATE));
  35.   System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
  36.   System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
  37.   System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
  38.   System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));

posted on 2012-09-19 09:51 japper 阅读(6338) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航: