Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6. Dates and Times > Converting YMDHMS to a Calendar or Epoch Seconds

Recipe 6.4. Converting YMDHMS to a Calendar or Epoch Seconds

6.5.1. Problem

You have year, month, day, hour, minute, and maybe even seconds, and you need to convert it to a Calendar or a Date.

6.5.2. Solution

Use the Calendar class's set(y,m,d,h,m[,s]) method, which allows you to set the date/time fields to whatever you wish. Note that when using this form and providing your own numbers, or when constructing either a Date or a GregorianCalendar object, the month value is zero-based while all the other values are true-origin. Presumably, this is to allow you to print the month name from an array without having to remember to subtract one, but it is still confusing.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial