Home > Backend Development > PHP Tutorial > Java converts the date string in the log output by Nginx into the Date type

Java converts the date string in the log output by Nginx into the Date type

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-08 09:32:53
Original
1226 people have browsed it

The original Nginx date data is: [28/Nov/2014:11:56:09 +0800]

Need to replace []:


<pre name="code">timeLocal = [28/Nov/2014:11:56:09 +0800]
Copy after login
timeLocal = timeLocal.replace("[", ""); timeLocal = timeLocal.replace("]", "");


Copy after login

There are a few things to note about the following formats:

(1) must be 3 M

(2)+0800 represents the time zone information, which can be parsed with Z

(3) must be Locale.ENGLISH, if it is written as CHINESE, an error will be reported


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));
Copy after login


The above introduces how Java converts the date string in the log output by Nginx into the Date type, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template