List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:Main.java
public static void main(String args[]) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal2.add(Calendar.HOUR, 2); cal2.add(Calendar.MINUTE, 42); cal2.add(Calendar.SECOND, 12); long secs = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 1000; String display = String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, (secs % 60)); System.out.println(display);/*from w w w . ja v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Hour in 12 hour format is : " + now.get(Calendar.HOUR)); System.out.println("Current Hour in 24 hour format is : " + now.get(Calendar.HOUR_OF_DAY)); System.out.println("Current Minute is : " + now.get(Calendar.MINUTE)); System.out.println("Current Second is : " + now.get(Calendar.SECOND)); System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar localTime = Calendar.getInstance(); localTime.set(Calendar.HOUR, 17); localTime.set(Calendar.MINUTE, 15); localTime.set(Calendar.SECOND, 20); int hour = localTime.get(Calendar.HOUR); int minute = localTime.get(Calendar.MINUTE); int second = localTime.get(Calendar.SECOND); System.out.printf("Local time : %02d:%02d:%02d\n", hour, minute, second); Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany")); germanyTime.setTimeInMillis(localTime.getTimeInMillis()); hour = germanyTime.get(Calendar.HOUR); minute = germanyTime.get(Calendar.MINUTE); second = germanyTime.get(Calendar.SECOND); System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = new GregorianCalendar(); // Get the components of the time int hour12 = cal.get(Calendar.HOUR); // 0..11 int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 int min = cal.get(Calendar.MINUTE); // 0..59 int sec = cal.get(Calendar.SECOND); // 0..59 int ms = cal.get(Calendar.MILLISECOND); // 0..999 int ampm = cal.get(Calendar.AM_PM); // 0=AM, 1=PM }
From source file:DateAddHour.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Original = " + calendar.getTime()); // Subtract 2 hour from the current time calendar.add(Calendar.HOUR, -2); // Add 30 minutes to the calendar time calendar.add(Calendar.MINUTE, 30); // Add 300 seconds to the calendar time calendar.add(Calendar.SECOND, 300); System.out.println("Updated = " + calendar.getTime()); }
From source file:DateAddHour.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Original = " + calendar.getTime()); // Substract 2 hour from the current time calendar.add(Calendar.HOUR, -2); // Add 30 minutes to the calendar time calendar.add(Calendar.MINUTE, 30); // Add 300 seconds to the calendar time calendar.add(Calendar.SECOND, 300); System.out.println("Updated = " + calendar.getTime()); }
From source file:MainClass.java
public static void main(String args[]) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); System.out.println(calendar.get(Calendar.MINUTE)); }
From source file:Main.java
public static void main(String[] args) { Date myDate;//from ww w.j a v a2 s .c om Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, 9); cal.set(Calendar.DATE, 24); cal.set(Calendar.YEAR, 2013); cal.set(Calendar.HOUR, 13); cal.set(Calendar.MINUTE, 45); cal.set(Calendar.SECOND, 52); myDate = cal.getTime(); System.out.println(myDate); }
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);/*w w w . j av a 2s .com*/ 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:CalendarManipulation.java
public static void main(String s[]) { Calendar cal = Calendar.getInstance(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM); System.out.println(df.format(cal.getTime())); cal.add(Calendar.HOUR, -4); System.out.println(df.format(cal.getTime())); }