- 真可
-
public Date getCST(String strGMT) throws ParseException {
DateFormat df = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH);
return df.parse(strGMT);
}
public String getGMT(Date dateCST) {
DateFormat df = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("GMT")); // modify Time Zone.
return(df.format(dateCST));
}
2种方法仅供参考,希望 采纳。
- 黑桃云
-
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+2"));
String snow = sdf.format(now);
System.out.println(snow);
- 牛云
-
String s = "2012-12-25 08:00:00";
SimpleDateFormat sd1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sd2 = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH);
Date d;
try {
d = sd1.parse(s);
sd2.setTimeZone(new SimpleTimeZone(28800000, "GMT"));
System.out.println(sd2.format(d));
} catch (ParseException e) {
e.printStackTrace();
}
- nicehost
-
学习了