`
liudaoru
  • 浏览: 1559217 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Date的toGMTString的替换方法

    博客分类:
  • java
 
阅读更多

由于Date类型的toGMTString已经不推荐使用,所以需要自己写将日期转为GMT格式的方法。

 

	/**
	 * 转化为标准时间
	 * @param date
	 * @return
	 */
	public static final String toGMT(Date date) {
		Locale aLocale = Locale.US;
		DateFormat fmt = new SimpleDateFormat("EEE,d MMM yyyy hh:mm:ss z", new DateFormatSymbols(aLocale));
		fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
		return fmt.format(date);
	}

 
2
0
分享到:
评论
2 楼 liudaoru 2009-10-16  
liuchong14 写道
  好复杂呀

如果嫌麻烦,可以继续用Date对象的toGMTString方法。
1 楼 liuchong14 2009-10-15  
  好复杂呀

相关推荐

    javascript文档

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    微软JavaScript手册

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    JScript 语言参考

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    JavaScript 中Date对象的格式化代码方法汇总

    很多时候,我们可以利用JavaScript中Date对象的内置方法来格式化,如: var d = new Date(); console.log(d); // 输出:Mon Nov 04 2013 21:50:33 GMT+0800 (中国标准时间) console.log(d.toDateString()); // 日期...

    javascript语言参考+教程 CHM

    toGMTString 方法; toLocaleDateString 方法; toLocaleLowerCase 方法; toLocaleString 方法; toLocaleTimeString 方法; toLocaleUpperCase 方法; toLowerCase 方法; toPrecision 方法; toString 方法; ...

    JS Date对象进行格式化日期

    const date = new Date(2019, 0, 23, 17, 23, 42) 格式化结果: toString: Wed Jan 23 2019 17:23:42 GMT+0800 (中国标准时间) toDateString: Wed Jan 23 2019 toLocaleString: 2019/1/23 下午5:23:42 ...

    JavaScript格式化日期时间的方法和自定义格式化函数示例

    很多时候,我们可以利用JavaScript中Date对象的内置方法来格式化,如: 代码如下:var d = new Date();console.log(d); // 输出:Mon Nov 04 2013 21:50:33 GMT+0800 (中国标准时间)console.log(d.toDateString()); /...

    JavaScript权威指南

    The Date Object Section 3.10. Regular Expressions Section 3.11. Error Objects Section 3.12. Primitive Data Type Wrapper Objects Chapter 4. Variables Section 4.1. Variable Typing Section...

    JS设置获取cookies的方法

    //设置cookie 方法一function setCookie(name,value){ var exp = new Date(); exp.setTime(exp.getTime() + 1*60*60*1000);//有效期1小时 [removed] = name + “=”+ escape (value) + “;expires=” + exp....

    javascript 操作cookies及正确使用cookies的属性

    var expiresDate = the_date.toGMTString(); [removed] = “userDefineCSS=” + escape(title) + “; expires=” + expiresDate; 第一句是日期对象; 第二句将日期格式转换成 GMT 格式;编者者: GMT 即格林威治...

    js设置cookie过期及清除浏览器对应名称的cookie

    代码如下: function ClearCookie() { var expires = new Date(); expires.setTime(expires.getTime() – 1000); //当前时间减去一秒,相当于立即过期(可以增减) [removed] = “appCode=’222”’;path=/;expires=” +...

    javascript cookies操作集合

    expires=”+date.toGMTString())+”;path=/”; str=str.replace(“2010″,”2099”); [removed]=str; alert(“恭喜,已成功屏蔽软件开发网所有广告,只要不清空Cookie,您都不会再受软件开发网广告困扰!”); /...

    静态网页统计流量静态网页统计流量

    expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "") if (!caution || (name + "=" + escape(value))...

    vue中设置、获取、删除cookie的方法

    1、在src目录下的access下新建一个cookie.js, 内容如下: export function setCookie(c_name,value,expire) {... expires="+date.toGMTString() //console.log([removed]) } export function getCookie(c_name){ if

    设置cooke和获取cooke的JS函数

    expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); [removed] = curCookie; } function getCookie...

    JavaScript对Cookie进行读写操作实例

    本文实例讲述了JavaScript对Cookie进行读写操作的方法。分享给大家供大家参考。具体如下: 这里没用到任何的js库,直接使用js的方法进行cookie的读写 ... var expdate="expires="+toexpire.toGMTString(); the_text+

    JS cookie中文乱码解决方法

    代码如下:function SetCookie(name, value) { var exp = new Date(); exp.setTime(exp.getTime() + 3 * 24 * 60 * 60 * 1000); //3天过期 [removed] = name + “=” + escape(value) + “;expires=” + exp....

    LocalStoreHelper.js

    var today = new Date(); var expiredate = new Date(); expiredate.setTime(today + 60 * 1000 * expire); [removed] = cookiename + "=" + escape(cookievalue) + ";expires=" + expiredate.toGMTString(); }...

    js读写(删除)Cookie实例详解

    代码如下: //JS操作cookies方法! //写cookies function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); [removed] = name + “=”+ escape ...

    详解Angular操作cookies方法

    本文介绍了Angular操作cookies方法,分享给大家,具体如下: var setCookie = function(name, value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); ...

Global site tag (gtag.js) - Google Analytics