您好,欢迎访问一九零五行业门户网

Java将Nginx输出的日志有日期字符串转成Date类型

原始的nginx日期数据为:[28/nov/2014:11:56:09 +0800]
需要将[]替换掉:
timelocal = [28/nov/2014:11:56:09 +0800]
timelocal = timelocal.replace([, );timelocal = timelocal.replace(], );

以下格式需要注意几点:
(1)必须是3个m
(2)+0800表示的是时区的信息,用z可以解析
(3)必须是locale.english,如果写成chinese会报错
simpledateformat formatter = new simpledateformat(dd/mmm/yyyy:hh:mm:ss z, locale.english);date date = formatter.parse(timelocal);simpledateformat format = new simpledateformat(yyyy-mm-dd hh:mm:ss);system.out.println(转换后的日期格式:+format.format(date));
以上就介绍了java将nginx输出的日志有日期字符串转成date类型,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
其它类似信息

推荐信息