Reputation: 13910
If unix timestamp is the same across the world how is am I able to get local time.
Or is it based on the different timezones the timestamp is different. i.e. I am in US the current seconds from UTC 1970 is 5,000 but if I am in Asia and check timestamp it will be 4,000 seconds ?
Upvotes: 0
Views: 2059
Reputation: 317
Both oldschool java.util.Date
and modern java.time.SystemClock
are using System#currentTimeMillis()
to get system time, so let's assume you have same Unix time value on both machines.
Unix time to local time conversion could be a Bachelor's degree thesis: you have to consider leap years, leap seconds, daylight savings time, some changes to country's timezones made by government. You can read more about all that in OpenJDK's tzdata sources.
So, you need both system time and tzdata to be the same on your machines.
Upvotes: 2
Reputation: 1153
I think epoch converter can answer your question:
http://www.epochconverter.com/
You will see that Unix time is the same across the world, and it will print date accordingly to your localization
Upvotes: 1
Reputation: 25593
UTC is the same for every country in the world, whether you check in the US or in Asia the value will be the same.
Local time is calculated by using a time-zone offset (usually provided through the IANA time zone database). This is added to UTC time to determine the "Local Time" since 1970.
Upvotes: 2