首页 > 代码库 > Java Calendar
Java Calendar
package com.qhong;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class Main { public static void main(String[] args) throws Exception { DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); System.out.println(df.format(new Date())); Calendar calendar=Calendar.getInstance(); Date dt=calendar.getTime(); System.out.println(df.format(dt)); System.out.println(calendar.getWeekYear()); System.out.println(calendar.getFirstDayOfWeek()); System.out.println(calendar.getWeeksInWeekYear()); System.out.println("===================="); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.DAY_OF_MONTH)); System.out.println(calendar.get(Calendar.DAY_OF_WEEK)); System.out.println(calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println(calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("===================="); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); System.out.println("===================="); System.out.println(calendar.get(Calendar.MILLISECOND)); Calendar NewCalendar=Calendar.getInstance(); NewCalendar.setTime(new Date()); System.out.println(df.format(NewCalendar.getTime())); NewCalendar.add(Calendar.YEAR,-1); System.out.println(df.format(NewCalendar.getTime())); NewCalendar.add(Calendar.MONTH,2); System.out.println(df.format(NewCalendar.getTime())); NewCalendar.add(Calendar.DATE,3); //后者大,显示 -1 System.out.println(df.format(NewCalendar.getTime())); System.out.println("时间比较:"+NewCalendar.compareTo(calendar)); //前者大,显示 1 NewCalendar.add(Calendar.YEAR,1); System.out.println("时间比较:"+NewCalendar.compareTo(calendar)); }}
2017-03-13 22:36:08:3932017-03-13 22:36:08:3942017152====================20172132272====================131022368====================3942017-03-13 22:36:08:3942016-03-13 22:36:08:3942016-05-13 22:36:08:3942016-05-16 22:36:08:394时间比较:-1时间比较:1
http://blog.csdn.net/joyous/article/details/9630893
http://sunnyhl.iteye.com/blog/1205820
Java Calendar
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。