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

    1.2018-08-01转日期格式

    Vue.prototype.strToGmt = function (str) {

     let GMT = new Date(str)

     return GMT

    }

    2.日期格式转2018-08-01

    Vue.prototype.gmtToStr = function (date) {
    var str = "";
    var hour = parseInt(date.getHours());
    var minnutes = parseInt(date.getMinutes());
    var seconds = parseInt(date.getSeconds());
    str += date.getFullYear() + "-";
    if (date.getMonth() + 1 < 10) {
      str += '0' + (date.getMonth() + 1) + "-";
    } else {
      str += (date.getMonth() + 1) + "-";
    }
    if (date.getDate() < 10) {
      str += '0' + date.getDate() + " ";
    } else {
      str += date.getDate() + " ";
    }
    // str += date.getDate() + " ";
    if (hour < 10) {
      str += "0" + hour + ":";
    } else {
      str += hour + ":";
    }

    if (minnutes < 10) {
      str += "0" + minnutes + ":"
    } else {
      str += minnutes + ":";
    }
    if (seconds < 10) {
      str += "0" + seconds
    } else {
      str += seconds;
    }
      return str
    }

    3.日期转化为 2017-08-09 不带时分秒

    Vue.prototype.getDateToStr = function (date) {
      var str = "";
      str += date.getFullYear() + "-";
      str += (date.getMonth() + 1) + "-";
      str += date.getDate() + " ";
      str += '00:00:00'
      return str
    }

    4.过滤日期时间(字符串),精确到日

    Vue.prototype.filterDateStr = function (str) {
      let newStr = '';
      newStr = str.substring(0, 10);
      return newStr
    }

  • 相关阅读:
    bzoj4950
    P1377发奖金
    环信SDK与Apple Watch的结合(1)
    环信SDK与Apple Watch的结合(2)
    【Objective-C】0-第一个OC的类
    【Objective-C】4-空指针和野指针
    【Objective-C】3 -self关键字
    【Objective-C】2.自定义构造方法和description方法
    Swift函数|闭包
    Swift枚举|结构体|类|属性|方法|下标脚本|继承
  • 原文地址:https://www.cnblogs.com/naxiaoming/p/9054710.html
Copyright © 2011-2022 走看看