Search code examples
javaandroiddatetimeutc

Having problems on getting actual time in UTC Android


I am trying to get the the day and time in UTC as milliseconds but repeatedly get the same problem. The result should be something like '63530139420000' but each time the value '1394547490884' is returned.

To get the date and time in UTC I use the following method:

long dateutc = System.currentTimeMillis();

Can anyone tell me what is the problem?


Solution

  • You can use this.

    DateFormat df = DateFormat.getTimeInstance();
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    String dateutc = df.format(new Date());