package org.xman.trainings.dates;


import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatTest {
    private static final String GMT_PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ";

    @Test
    public void testGmtPattern() {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(GMT_PATTERN);
        // 加上时区校正
        // sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

        System.out.println(sdf.format(now));
    }
}

@@ -110,16 +110,41 @@
 il.Date;
+%0Aimport java.util.Locale;
 %0A%0Apublic
@@ -214,34 +214,176 @@
 TERN
- = %22yyyy-MM-dd'T'HH:mm:ssZ
+_X = %22yyyy-MM-dd'T'HH:mm:ssXXX%22;%0A    private static final String GMT_PATTERN_Z = %22yyyy-MM-dd'T'HH:mm:ssZ%22;%0A%0A    private static final String T_PM_PATTERN = %22HH:mm:ss aaa
 %22;%0A%0A
@@ -422,16 +422,17 @@
 tPattern
+X
 () %7B%0A   
@@ -522,16 +522,18 @@
 _PATTERN
+_X
 );%0A     
@@ -648,16 +648,528 @@
 (now));%0A
+        // %E8%BE%93%E5%87%BA%E7%A4%BA%E4%BE%8B%EF%BC%9A2016-08-01T12:44:12+08:00%0A    %7D%0A%0A    @Test%0A    public void testGmtPatternZ() %7B%0A        Date now = new Date();%0A        SimpleDateFormat sdf = new SimpleDateFormat(GMT_PATTERN_Z);%0A%0A        System.out.println(sdf.format(now));%0A        // %E8%BE%93%E5%87%BA%E7%A4%BA%E4%BE%8B%EF%BC%9A2016-08-01T12:46:45+0800%0A    %7D%0A%0A    @Test%0A    public void testPmDate() %7B%0A        Date now = new Date();%0A        SimpleDateFormat sdf = new SimpleDateFormat(T_PM_PATTERN, Locale.US);%0A%0A        System.out.println(sdf.format(now));%0A        // %E8%BE%93%E5%87%BA%E7%A4%BA%E4%BE%8B%EF%BC%9A12:56:05 PM%0A
     %7D%0A%7D%0A

update date format sample with gmt\am\pm, etc.