字符串:"2016-09-21T18:57:50+08:00[Asia/Chungking]" 转Date

时间:2021-10-15 14:58:48

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");
Date date5 = sdf3.parse(str5);
System.out.println("str5:"+date5);
System.out.println(DateToZonedDateTimeConverter.INSTANCE.convert(date5));
}