List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. 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: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.MONTH)); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); System.out.println(calendar.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); int hour = japanCal.get(Calendar.HOUR); // 3 int minutes = japanCal.get(Calendar.MINUTE); // 0 int seconds = japanCal.get(Calendar.SECOND); // 0 boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true }
From source file:MainClass.java
public static void main(String[] args) { // get a calendar using the default time zone and locale. Calendar calendar = Calendar.getInstance(); // set Date portion to January 1, 1970 calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); // normalize the object calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); Date workDate = simpleDateFormat1.parse("2011-11-27"); Calendar workCalendar = Calendar.getInstance(); workCalendar.setTime(workDate);/* w ww . j a v a 2s . co m*/ SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm:ss"); Calendar time = Calendar.getInstance(); time.setTime(simpleDateFormat2.parse("06:00:00")); workCalendar.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY)); workCalendar.set(Calendar.MINUTE, time.get(Calendar.MINUTE)); workCalendar.set(Calendar.SECOND, time.get(Calendar.SECOND)); Date newWorkDate = workCalendar.getTime(); SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); System.out.println(simpleDateFormat3.format(newWorkDate)); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(); // current year value int year = gc.get(Calendar.YEAR); System.out.println(year);//w ww .j a va 2s . c o m // current month value int month = gc.get(Calendar.MONTH); System.out.println(month); // day of month int day = gc.get(Calendar.DAY_OF_MONTH); System.out.println(day); // hour value int hour = gc.get(Calendar.HOUR); System.out.println(hour); // minute value int minute = gc.get(Calendar.MINUTE); System.out.println(minute); // second values int second = gc.get(Calendar.SECOND); System.out.println(second); }
From source file:GregorianCalendarDemo.java
public static void main(String args[]) { String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int year;/*from w ww . ja va 2s . com*/ GregorianCalendar gcalendar = new GregorianCalendar(); System.out.print("Date: "); System.out.print(months[gcalendar.get(Calendar.MONTH)]); System.out.print(" " + gcalendar.get(Calendar.DATE) + " "); System.out.println(year = gcalendar.get(Calendar.YEAR)); System.out.print("Time: "); System.out.print(gcalendar.get(Calendar.HOUR) + ":"); System.out.print(gcalendar.get(Calendar.MINUTE) + ":"); System.out.println(gcalendar.get(Calendar.SECOND)); if (gcalendar.isLeapYear(year)) { System.out.println("The current year is a leap year"); } else { System.out.println("The current year is not a leap year"); } }