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"`
java转换日期格式为 RFC1123的更多相关文章
- SQLserver中用convert函数转换日期格式
SQLserver中用convert函数转换日期格式 2008-01-23 15:47 SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用con ...
- SQLserver中用convert函数转换日期格式(1)
SQLserver中用convert函数转换日期格式2008-01-15 15:51SQLserver中用convert函数转换日期格式 SQL Server中文版的默认的日期字段datetime格式 ...
- 时间戳转换日期格式 - Vue
日常开发中经常会遇到时间相关的问题,服务端返回的数据都是以时间戳的方式,那么需要将其处理转化为对应的时间格式,具体方式如下: 一.filters 中 formatDate 方法实现 <scrip ...
- java中日期格式的转换和应用
java中主要有3个类用于日期格式转换 DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...
- 【dateFormatSymbols】JAVA特殊日期格式转换
记录:特殊日期格式转换,如将yyyyMMdd转为01MAY2019 public static final String DATE_VIP_FORMAT = "yyyyMMdd"; ...
- java的日期格式使用
转自: 关于java中六个时间类的使用和区别 java.util.Date java.sql.Date java.sql.Time java.sql.Timestamp java.tex ...
- excel转换日期格式,将yyyymmdd类型日期转换成yyyy-mm-dd等日期类型方法
源数据日期格式:例如: 20160420 20160422 目标日期格式类型: 2016-4-20 2016-4-22 或 2016/04/20 2016/04/22 方法: 一.选中相应数据的单元格 ...
- Java中日期格式(String、Date、Calendar)的相互转换
package day20190318; import java.text.ParseException; import java.text.SimpleDateFormat; import java ...
- js时间戳转换日期格式和日期计算
一.时间戳转换日期 function formatDate(datetime) { // 获取年月日时分秒值 slice(-2)过滤掉大于10日期前面的0 var year = datetime.ge ...
随机推荐
- shell scripts 之 代码量统计
代码统计1 文件only中的内容为多个文件的文件名,code如下: xargs说明:xargs 读入stdin的值, 并默认以空白或者回车作为分隔符,将分割的值作为参数传给后面紧接着的的命令行操作.- ...
- Failed to load resource: the server responded with a status of 404 (Not Found) favicon.ico文件找不到
今天使用sublime以localhost方式打开html文件时(使用wamp环境提供一个Apache服务器,html文件存在于wamp环境的www文件夹下),出现favicon.ico文件找不到 ...
- pandas学习(数据分组与分组运算、离散化处理、数据合并)
pandas学习(数据分组与分组运算.离散化处理.数据合并) 目录 数据分组与分组运算 离散化处理 数据合并 数据分组与分组运算 GroupBy技术:实现数据的分组,和分组运算,作用类似于数据透视表 ...
- php在windows下发送邮件实现
一.使用PHP内置的mail()函数 看了一下手册,就直接开始写代码了,如下: <?php $to = "test@126.com"; //收件人 $subject = &q ...
- 2016年3月9日Android实习日记
1. 解决 org.eclipse.swt.SWTException: Graphic is disposed 问题. 参考:http://www.xuebuyuan.com/1896964.html ...
- ArcGIS中国工具2.5正式发布
ArcGIS中国工具2.5正式发布 1. 支持1:500,1:1000,1:2000的梯形接幅表和图框打印(见3.2) 2. 支持接幅表,一定间隔如1秒加节点生成并能自动识别打印(见3. ...
- css3 transition属性实现3d动画效果
transition属性是一个很强大的3d动画属性,我动手试了一下,很多在网上很火的网页动画都可以用这个属性实现,只能说这个属性是在是太强大啦,本人在学习次属性之后才知道自己对css3的认识还是偏少, ...
- Error-MVC:HTTP Error 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效。
ylbtech-Error-MVC:HTTP Error 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 1.返回顶部 1. IIS ...
- HOW TO REPLACE ALL OCCURRENCES OF A CHARACTER IN A STD::STRING
From: http://www.martinbroadhurst.com/replacing-all-occurrences-of-a-character-in-a-stdstring.html T ...
- 使用VirtualBox在Ubuntu下虚拟Windows XP共享文件夹设置方法
1.首先保证虚拟的Windows XP有虚拟光驱(正常安装的都是有的,因为在ubuntu下一般都是用硬盘虚拟安装的),然后在已经运行起来的Windows XP菜单栏上选择“设备-安装增强功能“,如果不 ...