EST 是 GMT-05:00,而 EEST 是 GMT+03:00。例如,在解析“Thu Apr 04 23:00:00 EEST 2013”时会出现差异。Java(7) 可以解析 EEST,但不能在 EEST 中格式化。
String s = "Thu Apr 04 23:00:00 EEST 2013";
SimpleDateFormat sdfParse = new SimpleDateFormat("E MMM d H:m:s z yyyy", Locale.ENGLISH);
Date d = sdfParse.parse(s);
SimpleTimeZone stz = new SimpleTimeZone(3 * 3600000 /* GMT+03:00 */, "EEST");
GregorianCalendar cal = new GregorianCalendar(stz, Locale.ENGLISH);
cal.setTime(d);
String ddmmyyyy = String.format("%02d/%02d/%4d", cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR));
System.out.println(s+"\n"+ddmmyyyy);
在 JavaScript 中:
function format2(s) {s="0"+s;return s.substr(s.length-2);}
function dateFormat(theDate) {
//theDate = "Thu Apr 04 00:00:00 EEST 2013";
var timestamp = Date.parse(theDate.replace(/EEST/, "GMT+0300"));
var datePseudoGMT = new Date(timestamp+3 * 3600000);
var dateCreation = format2(datePseudoGMT.getUTCDate())
+"/"+format2(datePseudoGMT.getUTCMonth()+1)
+"/"+format2(datePseudoGMT.getUTCFullYear());
console.log(dateCreation);
return dateCreation;
}