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