Home  >  Article  >  Backend Development  >  How to convert php timestamp to js

How to convert php timestamp to js

藏色散人
藏色散人Original
2020-10-16 09:47:481545browse

How to convert php timestamp to js: first open the corresponding code file; then use the "function to_date(phpstr) {...}" method to convert the php timestamp into js time.

How to convert php timestamp to js

Recommended: "PHP Video Tutorial"

Convert php timestamp to js time

  function to_date(phpstr) {
      str = parseInt(phpstr) * 1000;
      var newDate = new Date(str);
      var year = newDate.getUTCFullYear();
      var month = newDate.getUTCMonth() + 1;
      var nowday = newDate.getUTCDate();
      var hours = newDate.getHours();
      var minutes = newDate.getMinutes();
      var seconds = newDate.getSeconds();
      return year + "-" + month + "-" + nowday + " " + hours + ":" + minutes + ":" + seconds;//拼接 2017-2-21 12:23:43    }
  }

The above is the detailed content of How to convert php timestamp to js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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