How to Capture UTC with an Android App

Asked

Viewed 81 times

0

Good afternoon to all!

I need to capture, through an android app, which UTC used in the client device to make internal validations.

Thank you in advance!

  • 1

    What do you mean "which UTC"?

  • It’s about the time zone

  • See if http://www.joda.org/joda-time/ will help you

  • Thanks +Igor for the link, I’ll take a look here! Vlw

2 answers

1

Use the class Timezone.

TimeZone timeZone = TimeZone.getDefault();
String name = timeZone.getID();

The method getDefault() returns the Timezone the device is using.
The method getID() returns your ID, for example Portugal or Brazil/East.

  • Thank you +ramaral I will implement and perform some tests!

  • You accepted Edson’s reply, yet I was unaware if what you were looking for was what I answered or answered by him.

  • I will perform the tests yet, I accepted both for the sake of "pending", because I still do not know which one will work for me!

  • You cannot accept both at the same time. Do your tests and then come back to choose. I remind you that in addition to accepting you can vote on the answers.

  • Ahh ok then, thanks for the tip! I didn’t have that knowledge.

0

final Date currentTime = new Date();
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println("UTC time: " + sdf.format(currentTime));
  • Edson, could you explain your answer ? She’s joining the list of Low quality publications.

  • Thanks +Edson I will implement and perform some tests!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.