<script>

  //时间戳转日期,如:2024-12-25 
  function timestampToDateString(dateTime) {
      //console.log("dateTime", dateTime);
      if (dateTime) {
          var timestampStr = dateTime.replace("/Date(", "").replace(")/", "");//将 /Date(1735107000000)/  变成 1735107000000
          var timestamp = parseInt(timestampStr);//字符串转long
          const date = new Date(timestamp);
          //return date.toLocaleString().replace(" 00:00:00", "");
          var str = date.toLocaleString().replace(" 00:00:00", "");
          return str.replace("/", "-").replace("/", "-");
      }
      else {
          return "";
      }
  }

  //时间戳转日期时间,如:2024-12-25 14:45:25
  function timestampToDateTimeString(dateTime) {
      //console.log("dateTime", dateTime);
      if (dateTime) {
            var timestampStr = dateTime.replace("/Date(", "").replace(")/", "");//将 /Date(1730044800000)/  变成 1730044800000
            var timestamp = parseInt(timestampStr);//字符串转long
            var date = new Date(timestamp);

            Y = date.getFullYear() + '-';
            M = ((date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + '-';
            D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
            h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());

            return Y + M + D + h + m + s;
      }
      else {
          return "";
      }
  }

</script>

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐