November 2006
Intermediate to advanced
224 pages
3h 29m
English
// Date to Calendar conversion Date myDate = new java.util.Date(); Calendar myCal = Calendar.getInstance(); myCal.setTime(myDate); // Calendar to Date conversion Calendar newCal = Calendar.getInstance(); Date newDate = newCal.getTime(); |
If you’re working with times and dates, you’ll often find it necessary to convert between java Date and Calendar objects. Fortunately, as shown in the phrase, this is a very simple thing to do. A Calendar object has a setTime() method that takes a java.util.Date object as a parameter and sets the Calendar object to the date and time contained in the Date object passed in. To convert in the opposite direction, you can use the getTime() method of the Calendar class, which ...
Read now
Unlock full access