I want to get the year, month, date and hour from a long
timestamp value. I found many examples of creating a Calendar
from a timestamp value, but I don't get what I want.
I wrote the following
long timestamp = 1488866400;
Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis( timestamp );
System.out.println( cal.get( Calendar.YEAR ) );
System.out.println( cal.get( Calendar.MONTH ) );
System.out.println( cal.get( Calendar.DATE ) );
1488866400
is Tue, 07 Mar 2017 06:00:00 GMT, so I expected the code above to give me year 2017
, month 2
and date 7
, but it gives me year 1970
, month 0
and day 17
.
Can anyone tell me if I am doing anything wrong or if it could be made in a different way?