Error problems in CST time conversion

Source: Internet
Author: User
Tags cst time time zones

Error problem of CST time format


Scene: For example, the date directly identified in the database is ' Tue June 18:13:54 CST 2017 ', the normal conversion result is ' 2017-06-14 08:13:54 ', the result is 14 hours to me the whole of the depressed not, originally on this CST, GMT this time is vague, so I went online to check the Great God's post, after the record.


After conversion as shown (with error):


Cause of the error: CST can be said that the United States, Australia, Cuba, China 4 different time zones, GMT for Greenwich Mean Time, due to China in the East 8 region, the United States in the West 6 region, East plus West reduction so total difference of 14 hours. Because the Java Date conversion takes the United States time, it causes a time error.



Workaround:

public static void Main (string[] args) throws ParseException {
		String time = "Tue June 18:13:54 CST 2017";
		
		SimpleDateFormat SDF = new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz", yyyy);
		
		String formatdate = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (Sdf.parse (time)); 
		System.out.println (formatdate);
	}



Final effect:





Note that it is best to use GMT time to learn suggestions for your convenience.

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.