Could someone please explain in detail the following:
I have a long
value which represents a date
.
What will be the timezone
associated with the long
value?
How to convert the long
value to a date with proper time zone
?
Is there is way to identify the timezone
associated with the long date
value?
The Date class (which represents a specific instant in time) doesn't contain any time zone information. First, let's get the current UTC date and a TimeZone object: In Java 7, we need to use the Calendar class to represent a date with a time zone.
The basic steps in the calculation of day/date/time in a particular time zone: Obtain a new Date object. A date format object is created in Simple Date Format. The required format is assigned to the date format object – For Eg: hh:mm:ss.SSS. Set the required time zone to the date format object.
Using Java 8 Java 8 introduced a new Date-Time API for working with dates and times which was largely based off of the Joda-Time library. The Instant class from Java Date Time API models a single instantaneous point on the timeline in UTC. This represents the count of nanoseconds since the epoch of the first moment of 1970 UTC.
Pick the day/date/time value from the date format object by passing the date object created in the first step. The following table provides the various date patterns and their significance in Java Timestamp Format:
The long is milliseconds since Jan 1970, GMT. So, to that respect, it is GMT.
The long
value which represents the java.util.Date
is the number of milliseconds elapsed from epoch. (Jan 1, 1970)
/**
* Allocates a <code>Date</code> object and initializes it to
* represent the specified number of milliseconds since the
* standard base time known as "the epoch", namely January 1,
* 1970, 00:00:00 GMT.
*
* @param date the milliseconds since January 1, 1970, 00:00:00 GMT.
* @see java.lang.System#currentTimeMillis()
*/
public Date(long date) {
fastTime = date;
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With