Capturing UTC with an Android application [closed]

0

Good afternoon everyone!

I need to capture, through an android application, the UTC used on the client device to perform internal validations.

Thank you in advance!

    
asked by anonymous 08.12.2017 / 20:52

2 answers

1

Use the class TimeZone.

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

The getDefault () method returns the TimeZone that the device is to use. The method getID () returns your ID, for example Portugal or Brazil/East .

    
09.12.2017 / 11:56
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));
    
09.12.2017 / 03:47