I like surprises, I like puzzles, therefore I like Java Date and Calendar library. I already thought that there is nothing it could surprise me with. And I was wrong. Today it got me again. Consider the following code snippet.
Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, 0);//month is zero based calendar.set(Calendar.DAY_OF_MONTH, 1); Date date = calendar.getTime(); System.out.println(date); System.out.println(date.getTime());
The command on the line 07 prints out "
Thu Jan 01 00:00:00 GMT 1970", the question is what does the command on the line 08 prints? If you are such looser and you do not remember the JavaDoc of java.util.Date class, here is the description of getTime() method.
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
So to reformulate the question, what is the number of milliseconds between January 1, 1970, 00:00:00 GMT and Thu Jan 01 00:00:00 GMT 1970?
What are your guesses? Make yourself famous by adding a comment with correct explanation. And do not worry, if you do not find the solution until tomorrow evening, I will post it here.