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)); } }