• 获取当前时间封装(时间范围)


    src下边新建文件夹     例:utils

    再utils文件新建JS     例:dateFormat.js

    内容:

    /**
    * @part {[num]} 需要返回的天数 0 当前 -1昨天
    * @return {[date]} yyyy-mm-dd
    */
    export const dateChange = part => {
    let today = new Date();
    let targetday_milliseconds=today.getTime() + 1000*60*60*24*part;
    today.setTime(targetday_milliseconds);
    let tYear = today.getFullYear();
    let tMonth = today.getMonth();
    let tDate = today.getDate();
    tMonth = doHandleMonth(tMonth + 1);
    tDate = doHandleMonth(tDate);
    return tYear+"-"+tMonth+"-"+tDate;

    function doHandleMonth(month){
    let m = month;
    if(month.toString().length == 1){
      m = "0" + month;
    };
    return m;
    }
    }


    /**
    * 时间戳转YYYY-MM-DD
    * @param {[type]}
    * @return {[type]}
    */
    export const formatUnixtimestamp = unixtimestamp => {
    var unixtimestamp = new Date(unixtimestamp*1000);
    var year = 1900 + unixtimestamp.getYear();
    var month = "0" + (unixtimestamp.getMonth() + 1);
    var date = "0" + unixtimestamp.getDate();
    var hour = "0" + unixtimestamp.getHours();
    var minute = "0" + unixtimestamp.getMinutes();
    var second = "0" + unixtimestamp.getSeconds();
    return year + "-" + month.substring(month.length-2, month.length) + "-" + date.substring(date.length-2, date.length)
    + " " + hour.substring(hour.length-2, hour.length) + ":"
    + minute.substring(minute.length-2, minute.length) + ":"
    + second.substring(second.length-2, second.length);
    }

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    页面调用:import {dateChange} from '@/utils/dateFormat.js'

    方法调用:this.value1 = [dateChange(0)+' 00:00:00',dateChange(0)+' 23:59:59']

  • 相关阅读:
    测 试 报 告模板
    浅谈如何设计自动化测试框架
    GET与POST类型接口
    测试用例设计总结
    Java OO知识总结
    Java基础知识总结
    MIT 6.824学习笔记3 Go语言并发解析
    Go语言_并发
    MIT 6.824学习笔记4 Lab1
    Leetcode Lect3 二分法总结
  • 原文地址:https://www.cnblogs.com/PoisonousMushrooms/p/11972068.html
Copyright © 2020-2023  润新知