Neo*_*Neo 3 java string blackberry datetime-format java-me
我使用以下代码将字符串转换为日期,但它在转换时应用了设备的时区.
我不需要这个,但我希望从该字符串中获得相同的日期/时间
String = "2009-07-31 07:59:17.427"
Date = 2009-07-31 07:59:17.427
Date formatter = new Date(HttpDateParser.parse("2009-07-31 07:59:17.427"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String strCustomDateTime = dateFormat.format(formatter);
Run Code Online (Sandbox Code Playgroud)
您可以考虑解析后获得的默认时区偏移量:
public static String StringToDate(String dateToParse) {
Date formatter = new Date(HttpDateParser.parse(dateToParse));
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
int offset = TimeZone.getDefault().getRawOffset();
formatter.setTime(formatter.getTime() + offset);
String strCustomDateTime = dateFormat.format(formatter);
return strCustomDateTime;
}
Run Code Online (Sandbox Code Playgroud)