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(); // displays the current calendar System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll month cal.roll(Calendar.MONTH, true); // print result after rolling System.out.println("Month is " + cal.get(Calendar.MONTH)); // roll downwards cal.roll(Calendar.MONTH, false); // print result after rolling down System.out.println("Month is " + cal.get(Calendar.MONTH)); }
From source file:Main.java
public static void main(String[] args) { Calendar startEmployment = Calendar.getInstance(); startEmployment.set(2010, 2, 1);/* w w w.j a v a 2s . c o m*/ startEmployment.set(2011, Calendar.FEBRUARY, 1); Calendar now = Calendar.getInstance(); long numberOfDays1 = countDays(startEmployment, now); System.out.println(numberOfDays1); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar1 = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar1.set(2015, 01, 10);/* www.ja v a2 s . c o m*/ calendar2.set(2015, 07, 01); long milliseconds1 = calendar1.getTimeInMillis(); long milliseconds2 = calendar2.getTimeInMillis(); long diff = milliseconds2 - milliseconds1; long diffSeconds = diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); System.out.println("\nThe Date Different Example"); System.out.println("Time in milliseconds: " + diff + " milliseconds."); System.out.println("Time in seconds: " + diffSeconds + " seconds."); System.out.println("Time in minutes: " + diffMinutes + " minutes."); System.out.println("Time in hours: " + diffHours + " hours."); System.out.println("Time in days: " + diffDays + " days."); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); String n = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.ALL_STYLES, locale); System.out.printf(n);/*from ww w . j a va 2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); String n = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale); System.out.printf(n);/*from www . jav a 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); String n = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); System.out.printf(n);//from ww w . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Calendar cal = Calendar.getInstance(); // print current time in milliseconds System.out.println("Current time is : " + cal.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Calendar cal = Calendar.getInstance(); // print current time System.out.println(" Current time is : " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { int dayOfYear = 112; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, dayOfYear); System.out.println("Day of year " + dayOfYear + " = " + calendar.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar calTokyo = Calendar.getInstance(); calTokyo.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo")); System.out.println(// w w w .j a v a2 s.co m "Time in Tokyo: " + calTokyo.get(Calendar.HOUR_OF_DAY) + ":" + calTokyo.get(Calendar.MINUTE)); }