zoukankan      html  css  js  c++  java
  • java Calendar

    package com.cg.tests;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import java.util.TimeZone;
    
    import org.junit.Test;
    
    public class TestCalendar {
    	
    	@Test
    	public void testCalendar(){
    		/**按年月日构造日期时间对象**/
    		GregorianCalendar cal =new GregorianCalendar(1988, 1, 17);
    		
    		int iFirstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
    		int iLastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    		
    		Calendar calFirst =(Calendar) cal.clone();
    		Calendar calLast =(Calendar) cal.clone();
    				
    		calFirst.set(Calendar.DAY_OF_MONTH, iFirstDay);
    		calLast.set(Calendar.DAY_OF_MONTH, iLastDay);
    		
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		System.out.println(sdf.format( cal.getTime()));
    		System.out.println(sdf.format(calFirst.getTime()));
    		System.out.println(sdf.format(calLast.getTime()));
    		
    		/**时区**/
    		Calendar calNow = Calendar.getInstance();		//默认时区当前时间
    		System.out.println(sdf.format( calNow.getTime()));
    		
    		Calendar calGmt0 = Calendar.getInstance(TimeZone.getTimeZone("GMT-10"));
    //		calNow.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    		System.out.println(sdf.format( calGmt0.getTime()) );
    		System.out.println(calNow);
    		System.out.println(calGmt0);
    		
    		System.out.println("Hour of day: "+calNow.get(Calendar.HOUR_OF_DAY));
    		System.out.println("Hour of day: "+calGmt0.get(Calendar.HOUR_OF_DAY));
    		
    		System.out.println(calGmt0.get(Calendar.DAY_OF_MONTH));
    		
    	}
    
    }
    

      

  • 相关阅读:
    3305: Hero In Maze II (优先队列+bfs)
    2016年5月8日 GDCPC省赛总结
    POJ 2361 Tic Tac Toe
    about 字节
    KMP模式匹配
    scau 8616 汽车拉力比赛
    海盗分金--大于半数才成立
    scau 10692 XYM-入门之道
    函数模板和类模板成员函数的定义通常放在头文件中
    c语言运算符优先级巧记
  • 原文地址:https://www.cnblogs.com/wucg/p/2581957.html
Copyright © 2011-2022 走看看