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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM