Time conversion between Java time zones

Source: Internet
Author: User
Tags time zones local time

1SimpleDateFormat foo =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");2System.out.println ("foo:" + Foo.format (NewDate ()));3         4Calendar GC =gregoriancalendar.getinstance ();5System.out.println ("Gc.gettime ():" +gc.gettime ());6System.out.println ("Gc.gettimeinmillis ():" +NewDate (Gc.gettimeinmillis ()));7         8         //time of the current system default time zone:9Calendar Calendar =NewGregorianCalendar ();TenSystem.out.print ("Time zone:" + calendar.gettimezone (). GetID () + ""); OneSystem.out.println ("Time:" + calendar.get (calendar.hour_of_day) + ":" +Calendar.get (Calendar.minute)); A         //Los Angeles, USA time zone -TimeZone TZ = Timezone.gettimezone ("America/los_angeles"); -         //Time zone Conversion the 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 =NewDate (); +          -         //1. Get local time: +Java.util.Calendar cal =java.util.Calendar.getInstance (); A          at         //2. Get time offset: -         intZoneoffset =Cal.get (Java.util.Calendar.ZONE_OFFSET); -          -         //3, to obtain daylight saving time difference: -         intDstoffset =Cal.get (Java.util.Calendar.DST_OFFSET); -          in         //4. Deduct these differences from local time, that is, you can get UTC time: -Cal.add (Java.util.Calendar.MILLISECOND,-(Zoneoffset +dstoffset)); to          +         //The time taken after the cal.get (int x) or Cal.gettimeinmillis () method is called is the UTC standard Time.  -System.out.println ("UTC:" +NewDate (Cal.gettimeinmillis ())); the          *Calendar Calendar1 =calendar.getinstance (); $TimeZone Tztz = Timezone.gettimezone ("GMT");Panax Notoginseng Calendar1.settimezone (TZTZ); - System.out.println (Calendar.gettime ()); the System.out.println (Calendar.gettimeinmillis ()); +          A         //SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss ' Z '); the         //Df.settimezone (Timezone.gettimezone ("UTC")); +         //System.out.println (Df.parse ("2014-08-23t09:20:05z"). toString ()); -          $SimpleDateFormat DF1 =NewSimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss. SSS ' Z ' "); $Date T =NewDate (); - System.out.println (Df1.format (t)); -System.out.println (Df1.format (Df1.parse ("2014-08-27t18:02:59.676z") + "***********"); theDf1.settimezone (Timezone.gettimezone ("UTC")); - System.out.println (Df1.format (t));WuyiSystem.out.println ("-----------"); theSystem.out.println (Df1.format (Df1.parse ("2014-08-27t18:02:59.676z") + "***********"); -System.out.println ("2014-08-27t18:02:59.676z");

Time conversion between Java time zones

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.