1 public static void main(String[] args) { 2 //當前時間==>gmt 3 Date date=new Date(); 4 System.out.println("GMT時間"+date.toGMTString()); 5 //當前時間==>13時間戳 6 long l=date.getTime(); 7 System.out.println("時間戳"+l); 8 System.out.println("====================================="); 9 //gmt==>cst==>13位時間戳 10 try { 11 date=getCST("Sun, 11 Mar 2018 09:40:21 GMT"); 12 System.out.println("CST時間"+date); 13 System.out.println("時間戳"+date.getTime()); 14 } catch (ParseException e) { 15 // TODO Auto-generated catch block 16 e.printStackTrace(); 17 } 18 //時間戳==>gmt 19 String res; 20 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 21 long lt = new Long("1520757316886"); 22 Date datee = new Date(lt); 23 System.out.println("GMT時間"+datee.toGMTString()); 24 res = simpleDateFormat.format(datee); 25 26 System.out.println("CST時間"+res); 27 } 28 public static Date getCST(String strGMT) throws ParseException{ 29 DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH); 30 return df.parse(strGMT); 31 32 } 33 }