Import java. util .*;
Import java. text. SimpleDateFormat;
Import java. text. DateFormat;
Import static java. lang. System. out;
Public class CalendarTest
{
Public static void main (String [] args)
{
/*
* Get the current calendar time
*/
Calendar now = Calendar. getInstance ();
/**
* Obtain the number of milliseconds between the current time zone and the year of the calendar month.
*/
Long srcTime = now. getTimeInMillis ();
/**
* TimeZone. getDefault (). getRawOffset () is the current default time zone (GMT + 8) and GMT
* Original time zone deviation (milliseconds)
* The following formula is the Greenwich mean time corresponding to the current time zone (converted to the time corresponding to GMT)
*/
Long targetTime = srcTime-TimeZone.getDefault (). getRawOffset ();
/**
* Create Date
*/
Date newDate = new Date (targetTime );
/**
* Format the date
*/
DateFormat df = new SimpleDateFormat ("MM/dd/yyyy HH: mm: ss ");
// Df. setTimeZone (TimeZone. getTimeZone ("GMT "));
String str = df. format (newDate );
Out. println ("newDate:" + str );
}
}
This article is from the "Zuo Luo CTO" blog