java date eee_java转换日期格式为 RFC1123

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

import java.util.TimeZone;

public class GmtDate {

public static void main(String[] args){

System.out.println(new Date());

//本地日期格式.

String rfc1123_1 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.US).format(new Date());

System.out.println("rfc1123_1 = " + rfc1123_1);

//错误

String rfc1123_2 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'",Locale.US).format(new Date());

System.out.println("rfc1123_2 = " + rfc1123_2);

//正确, 推荐使用.

SimpleDateFormat sdf3 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.US);

sdf3.setTimeZone(TimeZone.getTimeZone("GMT"));

String rfc1123_3 = sdf3.format(new Date());

System.out.println("rfc1123_3 = "+rfc1123_3);

//正确.

SimpleDateFormat sdf4 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'",Locale.US);

sdf4.setTimeZone(TimeZone.getTimeZone("GMT"));

String rfc1123_4 = sdf4.format(new Date());

System.out.println("rfc1123_4 = " + rfc1123_4);

}

}

输出的结果

Tue Oct 30 15:33:48 CST 2018

rfc1123_1 = Tue, 30 Oct 2018 15:33:48 CST

rfc1123_2 = Tue, 30 Oct 2018 15:33:48 GMT

rfc1123_3 = Tue, 30 Oct 2018 07:33:48 GMT

rfc1123_4 = Tue, 30 Oct 2018 07:33:48 GMT

****************************************************

对应的命令

date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值