I do not know which one is right for get UTC time
My code is
System.currentTimeMillis()
for java android
Is the result correct
There is a common misconception around getting the correct "local" or "international" time. Time itself is unaware of these concepts, and I'll try to give an explanation here since other people still search for it.
Note that the following applies assuming that the machine clock is accurate in counting time, and initial time setup at boot was also correct. Also note that most connected devices will sync this internal clock with a network source from time to time to make it run accurately.
Time itself is something we don't control, it passes along one moment after another. But time presentation (seconds, hours, days, years, decades) is a human-created concept, made simply to understand the passage of time more clearly. You can imagine the confusion if we discussed time in moments - "Hey, I'm going to the store in 901400203150 moments, would you like to join?".
Anyway, the same is true for time zones, they are a human-created concept. We live on Earth, near the Sun and the Moon, and there is some revolving happening in space that made us recognize a longer time period called "year" and shorter ones called "month". We also recognized that morning comes earlier in some places, and later in others - thus, we introduced time calculations and time zones to make time tracking easier for everyone on the planet. But 10000 years ago, nobody knew about time zones, and yet time was passing by.
So, to answer the original question with that in mind: yes, that method will work, if you're interested in getting the absolute current time.
As mentioned, there is no such thing as "international" or "local" time, time is the same for everyone. We use these terms when referring to time value converted to and presented in a certain time zone format. Today we have something called Epoch (for humans: 00:00:00 UTC on 1 January 1970
, for most machines: 0
) - so fetching "milliseconds since Epoch" will give you the amount of raw time, expressed in milliseconds, passed since Epoch.
Time itself does not know about time zones or years or months, this is a human construct that you have to convert to on your own. Basically, what you get from the OS is raw time, and then you convert it to the desired time zone, desired format and language, to make it easier for the user to read. And how to convert time - that's a completely different question. :)