Java formatted CST date time

Source: Internet
Author: User
Tags locale set time

Date date = new Date (); SYSTEM.OUT.PRINTLN (date);

We will print out the Thu 18:05:49 CST format string in the console


The following code can be implemented to convert the time string in the CST format of Java into a Date object and the required datetime format!

String date = "Thu 18:05:49 CST 2015"; SimpleDateFormat SDF = new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz yyyy", locale.us);D ate d = sdf.parse (Date); String formatdate = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (d); System.out.println (formatdate);


Get GMT time code in Java:

Calendar cd = Calendar.getinstance (); SimpleDateFormat SDF = new SimpleDateFormat ("EEE d MMM yyyy HH:mm:ss ' GMT '", locale.us); Sdf.settimezone ( Timezone.gettimezone ("gmt+8")); Set time zone to GMT  +8 for Beijing time East eight zone string str = Sdf.format (Cd.gettime ()); System.out.println (str);


Itmyhome


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java formatted CST date time

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.