Could someone please explain in detail the following:
I have a long
value which represents a date
.
What will be the
timezone
associated with thelong
value?How to convert the
long
value to a date with propertime zone
?Is there is way to identify the
timezone
associated with thelong date
value?
When time is in long format,
TimeZone
won't be associated with it.You need to use either
SimpleDateFormat
(or)Calendar
API to apply Timezone for long value.The
long
value which represents thejava.util.Date
is the number of milliseconds elapsed from epoch. (Jan 1, 1970)What will be the timezone associated with the long value?
Can you attach a unit to a long value.? No.
This is akin to saying given an int 2 what does it represent? . It could be 2 miles or 2 pounds.
How to convert the long value to a date with proper time zone?
You can't because of above.
Is there is way to identify the timezone associated with the long date value?
Nope.
The long is milliseconds since Jan 1970, GMT. So, to that respect, it is GMT.
A Date (either as a long or a java.util.Date) represents a moment in time.
There is no TimeZone involved unless you're dealing with a Calendar.
You can create a Calendar for a given TimeZone and Locale like this: