2

When I use new Data().getTime(); with java in android, I can get the long value(13bits like 143XXXXX...XX), this value is determinded by the local time, when i change my android device local time, such as in advance or delay some hours, this value will be changed. How can I get the real unix timestamp disregard the local time and without using the network? thanks in advance!

1
  • If you're just changing the timezone, System.currentTimeMillis() will get the UTC time for you just fine. If you're futzing with system clock inaccuracies (for example, setting your clock faster ten minutes or something), afaik System.currentTimeMillis() will increase by 10 minutes correspondingly. The only way to get an accurate time would be to get a response from a time server and check against that. I like time.nist.gov myself. Commented Jul 20, 2015 at 8:08

2 Answers 2

1

what you probably want is

Systen.currentTimeMillis()

it returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

Sign up to request clarification or add additional context in comments.

Comments

1

What you are lookinh for is System.currentTimeMillis()

See the documentation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.