: This article describes how to convert a Date string to a Date type in the logs output by Nginx in Java. For more information about PHP tutorials, see. The original Nginx date data is: [28/Nov/2014: 11: 56: 09 + 0800]
Replace []:
timeLocal = [28/Nov/2014:11:56:09 +0800]
TimeLocal = timeLocal. replace ("[", ""); timeLocal = timeLocal. replace ("]", "");
Note the following:
(1) it must be 3 M
(2) + 0800 indicates the time zone information, which can be parsed using Z.
(3) it must be Locale. ENGLISH. if it is written as CHINESE, an error is returned.
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 ("converted date format:" + format. format (date ));
The preceding section describes how to convert the Date string in the logs output by Nginx to the Date type in Java, including the following content. I hope this will be helpful to anyone interested in the PHP Tutorial.