惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
Jina AI
Jina AI
雷峰网
雷峰网
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
美团技术团队
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - Franky
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
量子位
IT之家
IT之家
人人都是产品经理
人人都是产品经理
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - shcity

Troubleshooting on TransactionScope Parse string to JSON object blockUI doesn't close when download file in asp.net define namespace in JS Dense_Rank(), Row_Number(), Rank() in sql server reading and writing variable through lock in SSIS script task Fix the issue that cannot open SSIS in BIDS three ways creating custom helpers to show RadioButtonList in MVC using JavaScriptSerializer to serialize object to json using ISerializable to control serialization and deserialization ViewStateAutoManager ReportingService formatting Build my own DataTable split a string into an array through comma div with separated html template - shcity 正则表达式替换日期 半透明的div对话框 foreach 的自动转化类型 在Ajax1.0中调用页面CS文件中的方法
Parse date in js
shcity · 2013-07-09 · via 博客园 - shcity
<script type="text/javascript">
    var str1 = "3/01/2013";
    var str2 = "03/2/2013";

    var d1 = parseDate(str1).getTime();
    var d2 = parseDate(str2).getTime();

    if (d1 == d2) {
        alert("d1 == d2");
    }
    else if (d1 > d2) {
        alert("d1 > d2");
    }
    else {
        alert("d1 < d2");
    }

    function isDate(dateString) {

        var date = parseDate(dateString);

        if (date == null) return false;
        return true;
    }

    function parseDate(dateString) {

        var delimiter = "/";

        if (dateString.indexOf("-") > 0) {
            delimiter = "-";
        }

        var parts = dateString.split(delimiter);

        if (parts.length != 3) {
            return null;
        }

        /* mm/dd/yyyy or mm-dd-yyyy */
        var year = parts[2];
        var month = parts[0] - 1;
        var day = parts[1];

        var newDate = new Date(year, month, day);

        if (isNaN(newDate)) return null;

        if (newDate.getYear() == year
            && newDate.getMonth() == month
            && newDate.getDate() == day) {
            return newDate;
        }

        return null;
    }
</script>

posted on 2013-07-09 16:40  shcity  阅读(401)  评论()    收藏  举报