Java Reference
In-Depth Information
String dateStr = month + "/" + day + "/" + yr;
System.out.println(dateStr);
int dayOfWeek = gCal.get(Calendar.DAY_OF_WEEK);
// Print out the integer value for the day of the week
System.out.println(dayOfWeek);
int hour = gCal.get(Calendar.HOUR);
int min = gCal.get(Calendar.MINUTE);
int sec = gCal.get(Calendar.SECOND);
// Print out the time
System.out.println(hour + ":" + min + ":" + sec);
// Create new DateFormatSymbols instance to obtain the
String
// value for dates
DateFormatSymbols symbols = new DateFormatSymbols();
String[] days = symbols.getWeekdays();
System.out.println(days[dayOfWeek]);
// Get crazy with the date!
int dayOfYear = gCal.get(Calendar.DAY_OF_YEAR);
System.out.println(dayOfYear);
// Print the number of days left in the year
System.out.println("Days left in " + yr + ": "
+ (365-dayOfYear));
int week = gCal.get(Calendar.WEEK_OF_YEAR);
// Print the week of the year
System.out.println(week);
As demonstrated by this code, it is possible to obtain more detailed information re-
garding the current date when using the Calendar class. The results of running the
code will look like the following:
Search WWH ::




Custom Search