Mutual conversion of UTC (Java)

Source: Internet
Author: User
Tags los angeles time zone
Simpledateformat Foo = New Simpledateformat ("yyyy-mm-dd hh: mm: SS" ); System. Out. println ( "Foo:" + Foo. Format ( New  Date (); Calendar GC = Gregoriancalendar. getinstance (); system. Out. println ( "GC. gettime ():" + GC. gettime (); system. Out. println ( "GC. gettimeinmillis ():" + New  Date (GC. gettimeinmillis ()));  //  Default Time Zone of the current system: Calendar calendar = New  Gregoriancalendar (); system. Out. Print ( "Time Zone:" + calendar. gettimezone (). GETID () + "" ); System. Out. println ( "Time:" + calendar. Get (calendar. hour_of_day) + ":" + Calendar. Get (calendar. Minute ));  //  Los Angeles Time Zone Timezone TZ = timezone. gettimezone ("America/los_angeles" );  //  Time zone conversion  Calendar. settimezone (Tz); system. Out. Print ( "Time Zone:" + calendar. gettimezone (). GETID () + ""); System. Out. println ( "Time:" + calendar. Get (calendar. hour_of_day) + ":" + Calendar. Get (calendar. Minute); Date time = New  Date ();  //  1. obtain local time: Java. util. Calendar Cal = Java. util. Calendar. getinstance ();  //  2. Get the Time Offset:          Int Zoneoffset = Cal. Get (Java. util. Calendar. zone_offset );  // 3. Summer Time Difference:          Int Dstoffset = Cal. Get (Java. util. Calendar. dst_offset );  //  4. deduct these differences from the local time to obtain the UTC time: Cal. Add (Java. util. Calendar. millisecond,-(zoneoffset + Dstoffset ));  //  The time obtained by calling the Cal. Get (int x) or Cal. gettimeinmillis () method is the UTC Standard Time. System. Out. println ("UTC:" + New  Date (Cal. gettimeinmillis (); Calendar calendar1 =Calendar. getinstance (); timezone tztz = Timezone. gettimezone ("GMT" ); Calendar1.settimezone (tztz); system. Out. println (calendar. gettime (); system. Out. println (calendar. gettimeinmillis ()); 

 

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.