Java: Timezone why different timezone give same value in millisec

Why different Timezone give SAME value in millisec?

Because that’s what it’s meant to do. From the documentation:

(Returns) the current time as UTC milliseconds from the epoch.

In other words, it’s the value which would be in the Date returned by getTime – it doesn’t depend on the time zone. If you want values which depend on the time zone, use Calendar.Get(Calendar.YEAR) etc.

Both Calendar.getTime() and Calendar.getTimeInMillis() return values representing the instant in time within the calendar, which is independent of both time zone and calendar system.

Leave a Comment