首页  >  文章  >  web前端  >  json 日期数据转成日期字符串

json 日期数据转成日期字符串

巴扎黑
巴扎黑原创
2016-11-25 14:12:591216浏览

   function ChangeDateFormat(jsondate) {  

            jsondate = jsondate.replace("/Date(", "").replace(")/", "");  

              

            if (jsondate.indexOf("+") > 0) {  

                jsondate = jsondate.substring(0, jsondate.indexOf("+"));  

            } else if (jsondate.indexOf("-") > 0) {  

                jsondate = jsondate.substring(0, jsondate.indexOf("-"));  

            }  

            //alert(jsondate);  

            var date = new Date(parseInt(jsondate, 10));  

            //alert(date.getHours());  

            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;  

            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();  


            return date.getFullYear() + "-" + month + "-" + currentDate ;


        }  


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn