SHARE
TWEET

Date

a guest Mar 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Date;
  2. import java.util.Calendar;
  3.  
  4. public class testeDate {
  5.     public static void main(String[] args) {
  6.         System.out.println("Calendar");
  7.         Calendar calendar = Calendar.getInstance();
  8.  
  9.         int year       = calendar.get(Calendar.YEAR);
  10.         int month      = calendar.get(Calendar.MONTH + 1); // Jan = 0, dec = 11
  11.         int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
  12.         int dayOfWeek  = calendar.get(Calendar.DAY_OF_WEEK);
  13.         int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
  14.         int weekOfMonth= calendar.get(Calendar.WEEK_OF_MONTH);
  15.  
  16.         int hour       = calendar.get(Calendar.HOUR);        // 12 hour clock
  17.         int hourOfDay  = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock
  18.         int minute     = calendar.get(Calendar.MINUTE);
  19.         int second     = calendar.get(Calendar.SECOND);
  20.         int millisecond= calendar.get(Calendar.MILLISECOND);
  21.            
  22.         System.out.println("year \t\t: " + year);
  23.         System.out.println("month \t\t: " + month);
  24.         System.out.println("dayOfMonth \t: " + dayOfMonth);
  25.         System.out.println("dayOfWeek \t: " + dayOfWeek);
  26.         System.out.println("weekOfYear \t: " + weekOfYear);
  27.         System.out.println("weekOfMonth \t: " + weekOfMonth);
  28.            
  29.         System.out.println("hour \t\t: " + hour);
  30.         System.out.println("hourOfDay \t: " + hourOfDay);
  31.         System.out.println("minute \t\t: " + minute);
  32.         System.out.println("second \t\t: " + second);
  33.         System.out.println("millisecond \t: " + millisecond);
  34.     }  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top