如何在java脚本中检查字符串是否为日期时间类型

如何在java脚本中检查字符串是否为日期时间类型

本文介绍了如何在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.

推荐答案


var date = "02.26.2016 11:48:36"  

	if(!isNaN(Date.parse(date)))
	{
		document.write("Valid Date \n");
	}


这篇关于如何在java脚本中检查字符串是否为日期时间类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:33