Home > Web Front-end > JS Tutorial > body text

How to format Json to pass date

一个新手
Release: 2017-10-16 09:04:50
Original
2263 people have browsed it

Custom date type conversion function ChangeDateFormat, convert the function in the form of //Date(1294499956278+0800)// into the form of 2014-5-2


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("-"));
              }
              var date = new Date(parseInt(jsondate, 10));
              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;
          }
Copy after login

The above is the detailed content of How to format Json to pass date. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!