简体   繁体   English

隐藏日期字符串到日期对象?

[英]Covert Date String into Date Object?

I have a date object which has been saved as a string to a Cookie called LastDate 我有一个日期对象,该对象已作为字符串保存到名为LastDate的Cookie中

Reading the string from the cookie I get 从得到的cookie中读取字符串

$.cookie('LastDate'); = "Fri Jan 03 2014 00:00:00 GMT+0100 (CET)" =“ 2014年1月3日星期五00:00:00 GMT + 0100(CET)”

How can I convert this back into a date object in my code? 如何在我的代码中将其转换回日期对象? I have tried to do a Date.parse but that just returns seconds 我试图做一个Date.parse但只返回秒

Date.parse($.cookie('LastDate')); = 1388703600000 = 1388703600000

Is there a way to convert this string back to an actual date object? 有没有办法将此字符串转换回实际的日期对象?

Thanks 谢谢

To convert dateString back to Date object you just need to create a new object with dateString as parameter. 要将dateString转换回Date对象,您只需要创建一个以dateString作为参数的新对象。 In your case: 在您的情况下:

var dateObj = new Date($.cookie('LastDate'));

Please use bellow code: 请使用以下代码:

var newDate = new Date(); var newDate = new Date();

newDate = new Date($.cookie('LastDate')); newDate =新日期($ .cookie('LastDate'));

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM