Last active
December 14, 2015 08:49
-
-
Save wezoalves/5060300 to your computer and use it in GitHub Desktop.
JAVA - Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get times | |
Calendar now = Calendar.getInstance(); | |
int year = now.get(Calendar.YEAR); | |
int month = now.get(Calendar.MONTH); // Note: zero based! | |
int day = now.get(Calendar.DAY_OF_MONTH); | |
int hour = now.get(Calendar.HOUR_OF_DAY); | |
int minute = now.get(Calendar.MINUTE); | |
int second = now.get(Calendar.SECOND); | |
int millis = now.get(Calendar.MILLISECOND); | |
// end get times | |
// get start and end date of a year | |
Calendar cal = Calendar.getInstance(); | |
cal.set(Calendar.YEAR, 2012); | |
cal.set(Calendar.WEEK_OF_YEAR, 1); | |
cal.set(Calendar.DAY_OF_WEEK, 1); | |
Date start = cal.getTime(); | |
cal.set(Calendar.YEAR, 2012); | |
cal.set(Calendar.MONTH, 11); | |
cal.set(Calendar.DAY_OF_MONTH, 31); | |
Date end = cal.getTime(); | |
// end get start and end date of a year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment