Date as long value: how does TimeZone relate?

Could you please explain the following:

I have a long value that represents << 21>.

  • What will be the timezone associated with the long value?

  • How to convert long value to date with corresponding time zone ?

  • Is there a way to identify the timezone associated with a long date value?

+4
source share
4 answers

Duration - milliseconds since January 1970 GMT. So, in this respect it is GMT.

+6
source

A Date (either long or java.util.Date ) represents a point in time.

TimeZone is not involved if you are not dealing with a Calendar.

You can create a Calendar for a given TimeZone and Locale as follows:

 long rightNow = System.currentTimeMillis(); Locale exampleLocale = Locale.GERMANY; TimeZone zone = TimeZone.getTimeZone("EST"); Calendar theCalendar = Calendar.getInstance(zone, exampleLocale); theCaledar.setTime(new Date(rightNow)); 
+4
source

The long value that java.util.Date represents is the number of milliseconds elapsed since the era. (January 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 time zone associated with the long cost?
    Can you attach a block to a long value.? No.
    It is like saying int 2 what does it represent ?, It could be 2 miles or 2 pounds.

  • How to convert a long value to a date with the correct time zone?
    You cannot because of the above.

  • Is there a way to determine the time zone associated with a long date value?
    No.

+4
source

When the time is in long format, TimeZone will not be associated with it.

You need to use the SimpleDateFormat (or) Calendar API to apply Timezone for a long value.

+2
source

Source: https://habr.com/ru/post/1438331/


All Articles