zoukankan      html  css  js  c++  java
  • 日期戳格式转换

    不多说 上源码:

     1 function formatDate(dateString) {
     2     dateString = dateString.replace("/", "").replace("/", "").replace("Date", "").replace("(", "").replace(")", "").replace("-", "");
     3     var date = new Date(parseFloat(dateString));
     4     var year = date.getFullYear();
     5     var m = date.getMonth() + 1;
     6     var d = date.getDate();
     7     var reM = "" + m;
     8     if (reM.length == 1) {
     9         reM = "0" + m;
    10     }
    11     var reD = "" + d;
    12     if (reD.length == 1) {
    13         reD = "0" + d;
    14     }
    15 
    16     var h = "" + date.getHours();
    17     h = (h.length == 1) ? ("0" + h) : h;
    18     var M = "" + date.getMinutes();
    19     M = (M.length == 1) ? ("0" + M) : M;
    20     var s = "" + date.getSeconds();
    21     s = (s.length == 1) ? ("0" + s) : s;
    22     return year + "-" + reM + "-" + reD + " " + h + ":" + M + ":" + s;
    23 }
    View Code

    转换后格式为:

         yyyy-mm-dd hh:MM:ss

    注意:日期和时间之间存在空格。

  • 相关阅读:
    33. Search in Rotated Sorted Array
    文章
    导航
    页眉和页脚
    渐变
    图像翻转与子画面
    背景图像定位
    背景图像
    使用css将图像居中
    使用CSS将图像对齐
  • 原文地址:https://www.cnblogs.com/dabexiong/p/4993608.html
Copyright © 2011-2022 走看看