我有一个代码显示GMT时间,我需要在PST中显示它。我如何修改下面的代码来获取PST时间?如何在Java中将GMT更改为PST格式?
代码
public static final String FORMAT = "MM/dd/yyyy";
public static final String OUTPUT_FORMAT_STD_DATE6 = "MM/dd/yy hh:mm a";
public static final String INPUT_FORMAT_STD_TIMESTAMP = "yyyy-MM-dd HH:mm:ss";
public static String formatDate(String strDate, String inputFormat, String outputFormat) {
Date date = convertStringToDate(strDate,inputFormat);
String displayDateString = formatDate(date, outputFormat);
return displayDateString;
}
formatDate正在这里称为
public void endElement(String uri, String localName, String qName) throws SAXException {
if(EVENT.equalsIgnoreCase(qName)) {
auditEntries.add(entry);
} else if(LOG_TIME.equalsIgnoreCase(qName)) {
String time = content.toString();
entry.setLogTime(DateUtils.formatDate(time, "yyyy-MM-dd'T'HH:mm:ss", DateUtils.OUTPUT_FORMAT_STD_DATE6));
}
请帮帮忙,我在编写Java代码是新型B。
这就是我所做的。
public static String formatDate(String strDate, String inputFormat, String outputFormat) {
Date date = convertStringToDate(strDate,inputFormat);
DateFormat pstFormat = new SimpleDateFormat(outputFormat);
pstFormat.setTimeZone(TimeZone.getDefault());
String displayDateString = formatDate(date, outputFormat);
return displayDateString;
}
感谢
它是否总是格林威治标准时间到PST?如果是这样,最简单的方法可能是直接通过减去7小时来修改'formatDate()'函数中创建的日期。 – twain249
你的意思是日期 - 7? – Mike
@Mike参见[this](https://stackoverflow.com/questions/35212049/how-to-convert-time-from-gmt-to-pst)链接,以及[this](https:// stackoverflow .com/questions/13285904/how-to-convert-pst-to-gmt-0800-in-java)链接。 –