List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Calendar:" + cal.toString()); Date d = cal.getTime();// ww w . ja v a 2 s .c o m SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/yyyy HH:mm:ss"); System.out.println(sdf.format(d)); SimpleDateFormat sdfNew = new SimpleDateFormat("HH:mm:ss"); System.out.println(sdfNew.format(d)); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); // 15-04-2012 calendar.set(Calendar.DAY_OF_MONTH, 15); calendar.set(Calendar.YEAR, 2012); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MONTH, 3); Date start = calendar.getTime(); // 15-06-2012 calendar.set(Calendar.MONTH, 5); Date end = calendar.getTime(); calendar.setTime(start);//from ww w .jav a 2 s. c om Date d = null; while ((d = calendar.getTime()).before(end) || d.equals(end)) { int day = calendar.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { System.out.println(d); } calendar.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); int month = now.get(Calendar.MONTH); if (month == Calendar.JANUARY) { System.out.println("JANUARY"); }//from w ww . ja v a 2s . co m if (month == Calendar.FEBRUARY) { System.out.println("FEBRUARY"); } if (month == Calendar.MARCH) { System.out.println("MARCH"); } if (month == Calendar.APRIL) { System.out.println("APRIL"); } if (month == Calendar.MAY) { System.out.println("MAY"); } if (month == Calendar.JUNE) { System.out.println("JUNE"); } if (month == Calendar.JULY) { System.out.println("JULY"); } if (month == Calendar.AUGUST) { System.out.println("AUGUST"); } if (month == Calendar.SEPTEMBER) { System.out.println("SEPTEMBER"); } if (month == Calendar.OCTOBER) { System.out.println("OCTOBER"); } if (month == Calendar.NOVEMBER) { System.out.println("NOVEMBER"); } if (month == Calendar.DECEMBER) { System.out.println("DECEMBER"); } }
From source file:Main.java
public static void main(String[] args) { // create a calendar Calendar cal = Calendar.getInstance(); // get the time zone TimeZone tz = cal.getTimeZone(); // print the time zone name for this calendar System.out.println("The time zone is :" + tz.getDisplayName()); }
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); Date tomorrow = calendar.getTime(); if (tomorrow.after(today)) { System.out.println(tomorrow + " is after " + today); }/*www. j a v a 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { Date today = new Date(); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); Date yesterday = calendar.getTime(); if (yesterday.before(today)) { System.out.println(yesterday + " is before " + today); }//from w ww . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { Calendar start = Calendar.getInstance(); start.set(2015, 1, 21, 11, 1, 11);/* www . ja va 2 s.c o m*/ Calendar end = Calendar.getInstance(); Calendar clone = (Calendar) start.clone(); int year = elapsed(clone, end, Calendar.YEAR); System.out.println(year + " year"); clone.add(Calendar.YEAR, year); int month = elapsed(clone, end, Calendar.MONTH); clone.add(Calendar.MONTH, month); System.out.println(month + " month"); int date = elapsed(clone, end, Calendar.DATE); clone.add(Calendar.DATE, date); System.out.println(date + " day"); int hour = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 3600000; clone.add(Calendar.HOUR, hour); System.out.println(hour + " hour"); int minute = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 60000; clone.add(Calendar.MINUTE, minute); System.out.println(minute + " minute"); int millis = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 1000; System.out.println(millis + " millis"); }
From source file:MainClass.java
public static void main(String args[]) { Formatter fmt = new Formatter(); Calendar cal = Calendar.getInstance(); fmt = new Formatter(); fmt.format("%h", cal); System.out.println(fmt);//from ww w. ja v a2 s . c o m }
From source file:MainClass.java
public static void main(String args[]) { Formatter fmt = new Formatter(); Calendar cal = Calendar.getInstance(); fmt = new Formatter(); fmt.format("%tB %tb %tm", cal, cal, cal); System.out.println(fmt);// w w w . java 2 s . c o m }
From source file:MainClass.java
public static void main(String args[]) { Formatter fmt = new Formatter(); Calendar cal = Calendar.getInstance(); fmt.format("%tr", cal); System.out.println(fmt);//from w ww .j av a2 s . co m }