Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字符串到日期时间转换javascript_Javascript - Fatal编程技术网

字符串到日期时间转换javascript

字符串到日期时间转换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("/"

如何使用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("/");
        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>