Java time conversion will be due to time zone issues...

Source: Internet
Author: User
Tags dateformat
There are three examples, one of which is the format to be converted; you can copy it. Public static void main (string [] ARGs) {simpledateformat Sdf1 = newsimpledateformat ("yyyy-mm-dd hh: mm: SS ");Simpledateformat SDF = new simpledateformat ("eee Mmm DDHH: mm: ss z yyyy", locale. US ); String A = "Wed Jul 06 00:00:00 CST 2011"; // Date d = new date (a); system. out. println (SDF. format (new date (A); test (a); test1 (a);} public static void test (string time ){ Dateformat df = dateformat. getdatetimeinstance (dateformat. Full, dateformat. Full, locale. China ); Simpledateformat SDF = new simpledateformat ("eee Mmm dd hh: mm: SS 'cst 'yyyy", locale. US ); Try { System. Out. println (DF. Format (SDF. parse (time ))); } Catch (parseexception E) { System. Out. println ("Time Format error "); }} Public static void test1 (string ){ Simpledateformat bartdateformat = newsimpledateformat ("eee Mmm D hh: mm: ss z yyyy", java. util. locale. US ); Simpledateformat bartdateformat_1 = newsimpledateformat ("mm/DD/YYYY hh: mm: SS", java. util. locale. US ); String date = NULL; Date d = new date (); Try { D = bartdateformat. parse (); Date = bartdateformat_1.format (d ); } Catch (parseexception e ){ // Todo automatically generates catch Blocks E. printstacktrace (); } System. Out. println (date );}

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.