日期:2014-05-20  浏览次数:20692 次

如何解析这样的日期字符串
/Date(1260998851903+0100)/
上面这段日期字符串如何解析啊,路过的大侠们帮帮忙啊,谢谢了

------解决方案--------------------
上面的没有考虑到西半球时区,这里补充上
Java code
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));
    }
}