CST格式转GMT格式

在rss2.0的规范中,对于时间的要求比较苛刻,只能是gmt的时间格式。
格林威治时间,而在java的1.5的版本中,并没有toGMTString()这个方法
(以前有,现在没了,让取消了)。
那么,怎样让他按照格式输出呢。

首先来试试util包中的Date这个方法能得到什么东西。
Wed Mar 15 02:02:14 CST 2006

这个是CST的时间格式

ww-mm-dd-hh-mm-ss-yy CST

分析下GMT的时间格式

ww-dd-mm-yy-hh-mm-ss GMT

查api,1.5的,没有看到关于取这些值的函数。或者是我不会找:(

于是没办法了,

只好取得了字符串一个字一个字的取。

这个方法很死板,但是目前我只能想到这个解决方案。

Wed, 15 Mar 2006 03:32:25 GMT

这个是输出的结果,而在date的标准输出里面

输出结果是这个

Wed Mar 15 03:41:34 CST 2006

问题解决一个。rss的输出的时间的一个问题。

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Stringlew
 * Date: 2006-3-15
 * Time: 0:38:00
 * To change this template use File | Settings | File Templates.
 */


public class testtime {
    public testtime() {
        Date date = new Date();
        String angel = date.toString();
        String test[] = angel.split(" ");
        int j = test.length;
        String GMT = test[0] + ", " + test[2] + " " + test[1] + " " + test[5] + " " + test[3] + " GMT";
        System.out.print(GMT);


    }
    public static void main(String[] args){
          testtime ts=new testtime();
    }
}

Tags: cst gmt time

« 上一篇 | 下一篇 »

信息推荐

发表评论