GMT时间CST时间13位时间戳相互转换

 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 }

 

posted @ 2018-03-11 20:35  沃泽法克  阅读(3633)  评论(0)    收藏  举报