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"`

java转换日期格式为 RFC1123的更多相关文章

  1. SQLserver中用convert函数转换日期格式

    SQLserver中用convert函数转换日期格式 2008-01-23 15:47 SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用con ...

  2. SQLserver中用convert函数转换日期格式(1)

    SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用convert函数转换日期格式 SQL Server中文版的默认的日期字段datetime格式 ...

  3. 时间戳转换日期格式 - Vue

    日常开发中经常会遇到时间相关的问题,服务端返回的数据都是以时间戳的方式,那么需要将其处理转化为对应的时间格式,具体方式如下: 一.filters 中 formatDate 方法实现 <scrip ...

  4. java中日期格式的转换和应用

    java中主要有3个类用于日期格式转换    DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...

  5. 【dateFormatSymbols】JAVA特殊日期格式转换

    记录:特殊日期格式转换,如将yyyyMMdd转为01MAY2019 public static final String DATE_VIP_FORMAT = "yyyyMMdd"; ...

  6. java的日期格式使用

    转自:  关于java中六个时间类的使用和区别     java.util.Date java.sql.Date  java.sql.Time  java.sql.Timestamp java.tex ...

  7. excel转换日期格式,将yyyymmdd类型日期转换成yyyy-mm-dd等日期类型方法

    源数据日期格式:例如: 20160420 20160422 目标日期格式类型: 2016-4-20 2016-4-22 或 2016/04/20 2016/04/22 方法: 一.选中相应数据的单元格 ...

  8. Java中日期格式(String、Date、Calendar)的相互转换

    package day20190318; import java.text.ParseException; import java.text.SimpleDateFormat; import java ...

  9. js时间戳转换日期格式和日期计算

    一.时间戳转换日期 function formatDate(datetime) { // 获取年月日时分秒值 slice(-2)过滤掉大于10日期前面的0 var year = datetime.ge ...

随机推荐

  1. css 选择器、元素默认宽度、media screen

    @media screen and (min-width:800px){ .a{  background: url('../image/banner/banner1.jpg') no-repeat l ...

  2. Digital biquad filter

    Direct Form 1 The most straightforward implementation is the Direct Form 1, which has the following ...

  3. CentOS 6.4在运行XFS时系统crash的bug分析

    最近有一台CentOS 6.4的服务器发生多次crash,kernel version 是Linux 2.6.32-431.29.2.el6.x86_64.从vmcore-dmesg日志内容及cras ...

  4. element对象

    一.offset.client.scroll clientWidth,clientHeight,clientLeft,clientTop: offsetWidth,offsetHeight,offse ...

  5. c#textBox控件限制只允许输入数字及小数点

    在textboxd的事件中的 KeyPress 事件,这样双击进入代码:输入以下代码 即可 //判断按键是不是要输入的类型. || () && ( && () e.Ha ...

  6. psssss test

    我觉得我不该写博客了

  7. 洛谷.2325.[SCOI2005]王室联邦(贪心)

    题目链接 比较水的题 然而.. 首先可以考虑DFS 每B个分一个块,但是这样链底不会和上边相连 于是考虑从底下开始分,即在DFS完一个点时才将其加入栈中:当子树size==B时出栈 最后在根节点可能会 ...

  8. 在java中构建json对象,返回给前端页面

    // 给客户端返回一个json对象 StringBuilder sb = new StringBuilder("{"); sb.append("\"name\& ...

  9. centos7 重置root 密码

    重置Centos 7 Root密码的方式和Centos 6完全不同.让我来展示一下到底如何操作. 1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linu ...

  10. 如何实现跨域获取iframe子页面动态的url

    有的时候iframe的子页面会动态的切换页面,我们在父页面通过iframe1.contentWindow.window.location只能获取同源的子页面的信息.获取跨域的子页面信息会报错. 这时可 ...