LoginSignup
0
0

More than 5 years have passed since last update.

java SimpleDateFormat で UTC 取り扱い例

Posted at
HelloSimpleDateFormat4Main.java
package hello;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class HelloSimpleDateFormat4Main {

    public static void main(String[] args) throws Exception {
        // Fri May 13 01:18:07 UTC 2016

        String s = "Fri May 13 01:18:07 UTC 2016";

        SimpleDateFormat formatter = new SimpleDateFormat(
                "EEE MMM dd HH:mm:ss z yyyy", new Locale("en"));

        SimpleDateFormat formatter2 = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss z", new Locale("en"));
        {
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            formatter2.setTimeZone(cal.getTimeZone());
        }
        {
            Date d = formatter.parse(s);
            System.out.println(d);
            System.out.println(formatter2.format(d));
        }

    }

}

実行結果

Fri May 13 10:18:07 JST 2016
2016-05-13 01:18:07 UTC

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0