Java converts a Date string from the logs output by Nginx to the Date type.

Source: Internet
Author: User
: 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.