Calendar calendar = Calendar.getInstance();
System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); // print hour in 24 format
Showing posts with label Calendar. Show all posts
Showing posts with label Calendar. Show all posts
Friday, September 19, 2014
How to get hour value in 24 hour format
Thursday, September 18, 2014
Java Calendar - Calendar.MONTH is zero-based
Calendar calendar = Calendar.getInstance(); calendar.set(2010, 4, 10); System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
It's weird thing calendar.set(2010, 4, 10), actually set date as May 10, 2010. "4" for the MONTH field is really misleading. It sets Month as "May".
caalendar.getActualMaximum() calculates the maximum of days in month of May.
So output should be:
31
10
Wednesday, May 14, 2014
Java Date Format and Current Date Time
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
Subscribe to:
Posts (Atom)