日期:2014-05-20 浏览次数:20768 次
public static void main(String[] args) { String date = "/Date(1260998851903+0100)/"; Pattern pattern = Pattern.compile("/Date\\((\\d+)([\\+|\\-]\\d{2})(\\d{2})\\)/"); Matcher matcher = pattern.matcher(date); if (matcher.find()) { long milliseconds = Long.parseLong(matcher.group(1)); String timezone_hour = matcher.group(2); String timezone_minute = matcher.group(3); String timezone = "GMT" + timezone_hour + ":" + timezone_minute; TimeZone timeZone = TimeZone.getTimeZone(timezone); // 计算字符串中的时区与当前时区的时间差 long current_milli = System.currentTimeMillis(); long date_gmt_offset = timeZone.getOffset(current_milli); long local_gmt_offset = TimeZone.getDefault().getOffset(current_milli); long offset_to_local = local_gmt_offset - date_gmt_offset; // 输出字符串中的当地时间以及转换为本地的时间 System.out.println("当地时间:" + new Date(milliseconds)); System.out.println("本地时间:" + new Date(milliseconds + offset_to_local)); } }