字符串到日期时间转换javascript
如何使用java脚本将字符串(2010年4月9日)转换为日期时间(2010年4月9日00:00:00)?我需要比较验证日期。签出 试试这个应该行字符串到日期时间转换javascript,javascript,Javascript,如何使用java脚本将字符串(2010年4月9日)转换为日期时间(2010年4月9日00:00:00)?我需要比较验证日期。签出 试试这个应该行 <script language="javascript"> function validateDate(oSrc, args) { var iDay, iMonth, iYear; var arrValues; arrValues = args.Value.split("/"
<script language="javascript">
function validateDate(oSrc, args)
{
var iDay, iMonth, iYear;
var arrValues;
arrValues = args.Value.split("/");
iMonth = arrValues[0];
iDay = arrValues[1];
iYear = arrValues[2];
var testDate = new Date(iYear, iMonth - 1, iDay);
if ((testDate.getDate() != iDay) ||
(testDate.getMonth() != iMonth - 1) ||
(testDate.getFullYear() != iYear))
{
args.IsValid = false;
return;
}
return true;
}
</script>
函数validateDate(oSrc、args)
{
var iDay,iMonth,iYear;
var值;
arrValues=args.Value.split(“/”);
iMonth=arr值[0];
iDay=ARR值[1];
iYear=arrValues[2];
var testDate=新日期(iYear,iMonth-1,美国独立日);
如果((testDate.getDate()!=iDay)||
(testDate.getMonth()!=iMonth-1)||
(testDate.getFullYear()!=iYear))
{
args.IsValid=false;
返回;
}
返回true;
}
np。我知道它很旧,但我是通过谷歌来的,所以我想其他人可能还会来:)一个警告:Date.parse with ISO格式的日期('2010-04-01')在IE7上似乎不起作用,尽管它在Firefox和Chrome上也能起作用。
<script language="javascript">
function validateDate(oSrc, args)
{
var iDay, iMonth, iYear;
var arrValues;
arrValues = args.Value.split("/");
iMonth = arrValues[0];
iDay = arrValues[1];
iYear = arrValues[2];
var testDate = new Date(iYear, iMonth - 1, iDay);
if ((testDate.getDate() != iDay) ||
(testDate.getMonth() != iMonth - 1) ||
(testDate.getFullYear() != iYear))
{
args.IsValid = false;
return;
}
return true;
}
</script>