DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");年是小写的y。输入中与日期无关的任何字符(如“ T”中的字母)都应用
2013-03-13T20:59:31+0000引起来
''。
有关定义的模式字母的列表,请参见文档
解析检查给定日期是否为您指定的格式。要在检查后以特定格式打印日期,请参见以下内容:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");Date result;try { result = df.parse("2013-03-13T20:59:31+0000"); System.out.println("date:"+result); //prints date in current locale SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println(sdf.format(result)); //prints date in the format sdf}


