GMT and Beijing time of the mutual conversion, the background server is Greenwich time no processing on the lost to me,
Solve, a search on the internet, found that the problem in 10, or even 08 years have been proposed and resolved, to the predecessors salute,
Use, to summarize the useful:
"1 08 a buddy. The solution is to intercept the string conversion format:
String ts = "2007-10-23t17:15:44.000z";
System.out.println ("ts =" + ts);
ts = ts.replace ("Z", "UTC");
System.out.println ("ts =" + ts);
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd ' T ' HH:mm:ss. SSS Z ");
Date dt = sdf.parse (ts);
TimeZone TZ = Sdf.gettimezone ();
Calendar C = Sdf.getcalendar ();
System.out.println ("Display name:" + tz.getdisplayname ());
System.out.println (GetString (c));
See: http://devsharp.iteye.com/blog/170001
"2 Change Time zone:
Public String pasertime (int time) {
System.setproperty ("User.timezone", "Asia/shanghai");
TimeZone TZ = timezone.gettimezone ("Asia/shanghai");
Timezone.setdefault (TZ);
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String times = Format.format (new Date (Time * 1000L));
System.out.print ("date format---->" + times);
return times;
}
See: http://blog.csdn.net/xiaanming/article/details/8558547
"3 set to leap year, seconds, minutes, etc.
See: http://blog.sina.com.cn/s/blog_7fdd5eb901013iep.html
Pass six-bit parameters and intercept the judgment.
"4 Finally found the tool class.
Date Nowtime = new Date (); The time to convert
Calendar cal = Calendar.getinstance ();
Cal.settimeinmillis (Nowtime.gettime ());
LOG.I ("OTH", "Beijing Time:" + cal.gettime (). toString (). substring (0, 19));
Cal.add (Calendar.hour,-8);
LOG.I ("OTH", "GMT:" + cal.gettime ());
"5 Is there a better package?"
Package com.example.mydemo2012;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Java.util.Locale;
Import Java.util.TimeZone;
Class Gtmdateutil {
/**
* GTM Transfer to local time
*
* @param gtmdate
* @return
*/
@SuppressWarnings ("unused")
public string gtmtolocal (string gtmdate) {
int tindex = Gtmdate.indexof ("T");
String datetemp = gtmdate.substring (0, Tindex);
String timetemp = gtmdate.substring (Tindex + 1, gtmdate.length ()-6);
String convertstring = datetemp + "" + timetemp;
SimpleDateFormat format;
format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss", locale.english);
Date result_date;
Long result_time = 0;
if (null = = Gtmdate) {
return gtmdate;
} else {
try {
Format.settimezone (Timezone.gettimezone ("gmt00:00"));
Result_date = Format.parse (convertstring);
Result_time = Result_date.gettime ();
Format.settimezone (Timezone.getdefault ());
Return Format.format (Result_time);
} catch (Exception e) {
E.printstacktrace ();
}
}
return gtmdate;
}
/***
* It doesn't feel like going to Greenwich mean.
*/
public string Localtogtm (string localdate) {
SimpleDateFormat format;
format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss", locale.english);
Date result_date;
Long result_time = 0;
if (null = = Localdate) {
return localdate;
} else {
try {
Format.settimezone (Timezone.getdefault ());
Result_date = Format.parse (localdate);
Result_time = Result_date.gettime ();
Format.settimezone (Timezone.gettimezone ("gmt00:00"));
Return Format.format (Result_time);
} catch (Exception e) {
E.printstacktrace ();
}
}
return localdate;
}
}
Very good!
See: http://blog.csdn.net/sun6223508/article/details/45189841
> Get time Daquan, format conversion + leap year .... + +,
See: http://www.oschina.net/code/snippet_575610_22694
It's all sorted out:
http://download.csdn.net/detail/onebelowzero2012/9374733
Welcome to add, in addition to the C write the exe file to get GMT is also packaged.
GMT conversion and time conversion format Code Daquan