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

WBOY
WBOYOriginal
2016-08-08 09:32:531176browse

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]
timeLocal = timeLocal.replace("[", ""); timeLocal = timeLocal.replace("]", "");



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));


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.

Statement:
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