开发者

string to datetime conversion javascript

How do I convert string(09-Apr-2010) in to date time (09 April 2010 00:00:00) using java script? I need to compare the da开发者_如何学编程tes for validation.


check out Date.parse

str = "09-Apr-2010"
date = new Date(Date.parse(str.replace(/-/g, " ")))
alert(date.toLocaleString())


Try this should work

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜