zoukankan      html  css  js  c++  java
  • js 获取日期相关问题

    1.获取三个月之前的日期

    export function get3MonthBefor() {
      var resultDate, year, month, date, hms;
      var currDate = new Date();
      year = currDate.getFullYear();
      month = currDate.getMonth() + 1;
      date = currDate.getDate();
      hms = currDate.getHours() + ':' + currDate.getMinutes() + ':' + (currDate.getSeconds() < 10 ? '0' + currDate.getSeconds() : currDate.getSeconds());
      switch (month) {
        case 1:
        case 2:
        case 3:
        month += 9;
        year--;
        break;
        default:
        month -= 3;
        break;
      }
      month = (month < 10) ? ('0' + month) : month;
      resultDate = year + '-' + month + '-' + date
      // resultDate = year + '-' + month + '-' + date + ' ' + hms;
      return resultDate;
    }
     
    2.时间戳转日期
     

    export const timeFormat = (timestamp) => {
      if (timestamp) {
        var date = new Date(timestamp * 1000);
      } else {
      var date = new Date();
      }
      let Y = date.getFullYear(),
      m = date.getMonth() + 1,
      d = date.getDate(),
      H = date.getHours(),
      i = date.getMinutes(),
      s = date.getSeconds();
      if (m < 10) {
        m = '0' + m;
      }
      if (d < 10) {
        d = '0' + d;
      }
      if (H < 10) {
        H = '0' + H;
      }
      if (i < 10) {
        i = '0' + i;
      }
      if (s < 10) {
        s = '0' + s;
      }
      var t = Y + '-' + m + '-' + d + ' ' + H + ':' + i + ':' + s;
      return t;
    }

  • 相关阅读:
    分析报告生产器使用问题
    如何使用分析报告生产器来生产图表
    基础数据代换代码
    浅谈Session与Cookie的区别与联系
    TCP和UDP的区别(转)
    项目管理技巧-怎么让代码规范执行下去
    吾日三省吾身
    C# 类型基础
    泛型
    事件与委托(续)
  • 原文地址:https://www.cnblogs.com/wusheng2016/p/8252261.html
Copyright © 2011-2022 走看看