2016-09-21T18:57:50+08:00[Asia/Chungking]

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


import com.dedao.tplatform.util.JSR310DateConverters.DateToZonedDateTimeConverter;


public class test {


public static void main(String[] args) throws Exception {


Date date1 = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String str1 = df.format(date1);
System.out.println("yyyy-MM-dd'T'HH:mm:ssZ:"+str1);

String str2="2016-10-10T14:54:25+0800";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Date date2 = sdf.parse(str2);
System.out.println(date2);

Date date3 = new Date();
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
String str3 = df2.format(date3);
System.out.println("yyyy-MM-dd'T'HH:mm:ssXXX:"+str3);

String str4="2016-10-10T14:54:25+08:00";
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
Date date4 = sdf2.parse(str4);
System.out.println(date4);

String str5="2016-09-21T18:57:50+08:00[Asia/Chungking]";
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
sdf3.setTimeZone(TimeZone.getDefault());

Date date5 = sdf3.parse(str5);
System.out.println("str5:"+date5);
System.out.println(DateToZonedDateTimeConverter.INSTANCE.convert(date5));
}


}

你可能感兴趣的:(jAVA)