Java UTC time

Source: Internet
Author: User

Calendar lastDate = Calendar. getInstance (); </p> <p> DateFormat gmtFormat = new SimpleDateFormat (); <br/> TimeZone gmtTime = TimeZone. getTimeZone ("UTC"); </p> <p> gmtFormat. setTimeZone (gmtTime); <br/> Calendar calendar = java. util. calendar. getInstance (); </p> <p> System. out. println ("GMT Time:" + calendar. getTime (); </p> <p> System. out. println ("UTC Time:" + gmtFormat. format (calendar. getTime (); </p> <p>

 

Simpledateformat Foo = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); <br/> system. out. println ("foo:" + Foo. format (new date (); </P> <p> calendar GC = gregoriancalendar. getinstance (); <br/> system. out. println ("GC. gettime (): "+ GC. gettime (); <br/> system. out. println ("GC. gettimeinmillis (): "+ new date (GC. gettimeinmillis (); </P> <p> // time of the Current System Default Time Zone: <br/> calendar = new gregoriancalendar (); <br/> system. out. P RINT ("Time Zone:" + calendar. gettimezone (). GETID () + ""); <br/> system. out. println ("time:" + calendar. get (calendar. hour_of_day) + ":" + calendar. get (calendar. minute); <br/> // us time zone in Los Angeles <br/> timezone TZ = timezone. gettimezone ("America/los_angeles"); <br/> // time zone conversion <br/> calendar. settimezone (Tz); <br/> system. out. print ("Time Zone:" + calendar. gettimezone (). GETID () + ""); <br/> system. out. println ("time:" + calendar. get (calendar. hour_of_day) +": "+ Calendar. get (calendar. minute); <br/> date time = new date (); </P> <p> // 1. Obtain the local time: <br/> JAVA. util. calendar Cal = Java. util. calendar. getinstance (); </P> <p> // 2. Get Time Offset: <br/> int zoneoffset = Cal. get (Java. util. calendar. zone_offset); </P> <p> // 3. Time Difference in summer: <br/> int dstoffset = Cal. get (Java. util. calendar. dst_offset); </P> <p> // 4. deduct these differences from the local time to obtain the UTC time: <br/> Cal. add (Java. util. calendar. millisecond,-(zoneoffse T + dstoffset); </P> <p> // The time obtained by calling Cal. Get (int x) or Cal. gettimeinmillis () is the UTC Standard Time. <Br/> system. out. println ("UTC:" + new date (Cal. gettimeinmillis (); </P> <p> calendar calendar1 = calendar. getinstance (); <br/> timezone tztz = timezone. gettimezone ("GMT"); <br/> calendar1.settimezone (tztz); <br/> system. out. println (calendar. gettime (); <br/> system. out. println (calendar. gettimeinmillis ());

 

 

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.