/Date(1260998851903+0100)/
上面这段日期字符串如何解析啊,路过的大侠们帮帮忙啊,谢谢了
上面这段日期字符串如何解析啊,路过的大侠们帮帮忙啊,谢谢了
解决方案 »
- Cannot create PoolableConnectionFactory (尝试连线已失败。)
- 实现JPanel圆角边框
- IP输入框的问题——程序不能运行,谁帮我看看
- 对正则表达式中包含*的,如何使用分组?? 请各位高手指教! 谢谢~~
- JAVA语法问题??
- 这两种做法是否有效率差别?为什么?简单程序。
- 高手请进
- 最最最最最最 基础的问题了
- 我是不是异想天开呀?
- 有几个小地方不懂 细致的大虾来解答下
- java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-base
- 做了一个Java版的俄罗斯方块
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; // 计算字符串中的时区与当前时区的时间差
long current_milli = System.currentTimeMillis();
TimeZone timeZone = TimeZone.getTimeZone(timezone);
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));
}
}
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));
}
}