如何在java脚本中检查字符串是否为日期时间类型。 [英] How to check if a string is date time type in java script.
本文介绍了如何在java脚本中检查字符串是否为日期时间类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Please don't mark this as the duplicate. I found many answers to check if string is of type date without adding any jquery libraries.But Couldn't find anything.
function IsDate() { var date = "26.02.2016 11:48:36" return Date.Parse(new Date("26.02.2016 11:48:36")); }
The above code says the date is invalid but it is a valid date. Can any one please let me know how to check this kind of string value as date type in Jquery/Javascript?
我的尝试:
What I have tried:
Many Solutions suggested to use Date.Parse() method or use datejs external library. For the string "26.02.2016 11:48:36" but the Date.Parse() method returns "Nan" where as it had to say as valid date.
推荐答案
JavaScript Date.parse()接受 RF 2822 [ ^ ]或https://www.w3.org/TR/NOTE-datetime格式 - 你的字符串都不是......
JavaScript Date.parse() accepts dates in RF 2822[^] or https://www.w3.org/TR/NOTE-datetime format - your string is none of them...
你好!
你应该注意的几件事:
> Date.Parse不是有效的javascript函数,而不是使用Date.parse,返回no。从1970年1月1日到指定日期之间的毫秒数。
> Javascript不支持dd / mm / yyyy格式。因此,您的代码可能会返回无效日期。所以,使用mm / dd / yyyy格式而不是。
Hello there!
Few things you should mind:
> Date.Parse is not a valid javascript function instead of use Date.parse and this return no. of millseconds between 1/1/1970 and to specified date.
> Javascript doesn't support dd/mm/yyyy format. So, your code might return Invalid date. So, use mm/dd/yyyy format instead of that.
var date = "02.26.2016 11:48:36"
if(!isNaN(Date.parse(date)))
{
document.write("Valid Date \n");
}
这篇关于如何在java脚本中检查字符串是否为日期时间类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文