Java SimpleDateFormat get UTC Time String

Description

Java SimpleDateFormat get UTC Time String


import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;


public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getUTCTimeString());
    }/* w  w w  .j ava2  s .  c  o m*/

    public static String getUTCTimeString() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("utc"));
        return format.format(new Date());
    }
}



PreviousNext

Related