CST和GMT

GMT(Greenwich Mean Time)代表格林尼治标准时间,这个大家都知道。  
而CST却同时可以代表如下 4 个不同的时区:  
Central Standard Time (USA) UT-6:00 
Central Standard Time (Australia) UT+9:30 
China Standard Time UT+8:00 
Cuba Standard Time UT-4:00  
 
可见,CST可以同时表示美国,澳大利亚,中国,古巴四个国家的标准时间。  
 
前面提到的通过 Java 获取的CST时间用的是China Standard Time,而客户端JavaScript则默认采用的是美国
的中部时间。  
 
所以将 Fri Aug 28 09:37:46 CST 2009 加上 6 个小时,再加上 8 个小时,就等于 Fri Aug 28 2009 23:37:46
GMT+0800  
 
可见,在以后的编程中为了避免错误,还是不要使用CST时间,而尽量采用GMT时间。

GMT与CST的转换

方法一: 
Date date = new Date(); 
date.toGMTString();   // jdk高版本中,已经过时,不推荐。 

方法二: 
DateFormat cstFormat = new SimpleDateFormat(); 
DateFormat gmtFormat = new SimpleDateFormat(); 
TimeZone gmtTime = TimeZone.getTimeZone("GMT"); 
TimeZone cstTime = TimeZone.getTimeZone("CST");       
cstFormat.setTimeZone(gmtTime); 
gmtFormat.setTimeZone(cstTime); 
System.out.println("GMT Time: " + cstFormat.format(date)); 
System.out.println("CST Time: " + gmtFormat.format(date)); 

方法三: 
public Date getCST(String strGMT) throws ParseException { 
   DateFormat df = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH); 
   return df.parse(strGMT); 


public String getGMT(Date dateCST) { 
   DateFormat df = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH); 
   df.setTimeZone(TimeZone.getTimeZone("GMT")); // modify Time Zone. 
   return(df.format(dateCST)); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值