如何转换的JavaScript字符串格式日期 [英] How to convert javascript string format to date
本文介绍了如何转换的JavaScript字符串格式日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 AJAX
的成功的我收到 result.Date
为/日(-2208967200000)/
。我需要检查以下日期,并继续..
如何在转换/日(-2208967200000)/
到1900年1月1日
下面如果
条件?
如果(result.Date!=1900年1月1日){
....
}
解决方案
您可以将result.Date为您比较日期格式,同下面的例子
VAR dateString =\ /日期(-2208967200000)\ /SUBSTR(6)。
VAR currentTime的=新的日期(parseInt函数(dateString));
变种一个月= currentTime.getMonth()+ 1;
变种天= currentTime.getDate();
VAR年= currentTime.getFullYear();
VAR日期=日+/+月+/+年;
这样做后..你可以将它与其他日期进行比较。
In my ajax
success I am getting result.Date
as "/Date(-2208967200000)/"
. I need to check with the following date and proceed..
How to convert the "/Date(-2208967200000)/"
to "01-01-1900"
for below if
condition?
if (result.Date != "01-01-1900") {
....
}
解决方案
You can convert result.Date into you comparison date format, same as below example
var dateString = "\/Date(-2208967200000)\/".substr(6);
var currentTime = new Date(parseInt(dateString ));
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var date = day + "/" + month + "/" + year;
After doing this.. you can compare it with other date..
这篇关于如何转换的JavaScript字符串格式日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文