请帮助将格式为“ 2007年5月16日上午12:00:00 ”的格式转换为GMT数据格式,如 java中的“ 2007-05-16T12:00:00.000 + 0000 ” 使用以下方法
public String getGMTMillis(Date time)
{
if (time != null)
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
return "" + calendar.getTimeInMillis();
}
return "";
}
答案 0 :(得分:1)
尝试:
public String getGmtMillis(Date time)
{
if (time == null)
{
return "";
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(time);
}
答案 1 :(得分:0)