Home > Web Front-end > JS Tutorial > Convert json date data into date string

Convert json date data into date string

巴扎黑
Release: 2016-11-25 14:12:59
Original
1292 people have browsed it

   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 ;


        }  


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template