笨小孩做开发

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

    <script type="text/javascript">
    function MyFun(date2 ,  date1)
    {

    var type1 = typeof date1, type2 = typeof date2;
    if(type1 == 'string')
    date1 = stringToTime(date1);
    else if(date1.getTime)
    date1 = date1.getTime();
    if(type2 == 'string')
    date2 = stringToTime(date2);
    else if(date2.getTime)
    date2 = date2.getTime();
    var type3 = (date1 - date2) / (24*60*60*1000);
    if (type3<0)
     type3 =0;
     else

    return  type3;
    }

    function stringToTime(string){
    var f = string.split(' ', 2);
    var d = (f[0] ? f[0] : '').split('-', 3);
    var t = (f[1] ? f[1] : '').split(':', 3);
    return (new Date(
    parseInt(d[0], 10) || null,
    (parseInt(d[1], 10) || 1)-1,
    parseInt(d[2], 10) || null,
    parseInt(t[0], 10) || null,
    parseInt(t[1], 10) || null,
    parseInt(t[2], 10) || null
    )).getTime();
}

    </script>

 

posted on 2013-03-11 14:13  笨小孩做开发  阅读(272)  评论(0编辑  收藏  举报