vue使用中的问题,经验

vue开发中遇到的问题的记录
@TOC##在vue中按时间段(本周,本月,本季度,本年)查询?

一,在vue中按时间段(本周,本月,本季度,本年)查询?

  1. 在src下的utils中建文件dateTimeutils.js,代码如下
/**
 * @Created by xfl on 2019/6/10
 */
exports.install = function (Vue, options) {

  // 时间格式化
  Vue.prototype.format_date = function (DateFor){//全局函数1
    let year = DateFor.getFullYear()
    let month = DateFor.getMonth() + 1
    let day = DateFor.getDate()
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (day >= 0 && day <= 9) {
      day = "0" + day;
    }
    let tmp= year + '-' + month + '-' + day
    return tmp
  };

  /**
   * 获取月初,获取 当前月+gap 的月初(若gap为-1,则获取上月初,若gap为1,则获取下月初,
   * @param date 若date为空,则获取当前月的
   * @param gap
   * @returns {string}
   */
  Vue.prototype.get_month_first = function (date,gap){
    let date1 = new Date();
    if(date){
      date1= new Date(date);
    }
    // 获取间隔月
    let gapMonth = date1.getMonth() + gap
    // 获取间隔月月初
    let gapMonthFirstDay=new Date(date1.getFullYear(),gapMonth,1);
    let firstDay = this.format_date(gapMonthFirstDay)
    console.log(firstDay)
    return firstDay
  };

  // 获取月末
  Vue.prototype.get_month_last = function (date,gap){ 
    // gap = gap + 1
    let date1 = new Date()
    if(date){
      date1= new Date(date);
    }
    // 获取下个月月初
    let gapMonth = date1.getMonth()
    gapMonth = gapMonth + 1 + gap

    let NextMonthFirstDay=new Date(date1.getFullYear(),gapMonth,1)
    NextMonthFirstDay = NextMonthFirstDay.getTime() - 1000*60*60*24
    let temp = new Date()
    temp.setTime(NextMonthFirstDay)
    let lastDay = this.format_date(temp)
    return lastDay
  };

  /**
   * 获取日期函数,
   * @param dateTime 若为空则返回当前日期
   * @param gap 若gap=0,则为系统日期,若不为0,则当期日期-gap(当前日期减去gap这个数值的日期)
   * @returns {string}
   */
  Vue.prototype.get_date = function (dateTime,gap){
    let date = new Date()
    if(dateTime){
      date= new Date(dateTime);
    }
    date = date.getTime() - 1000*60*60*24*gap
    let temp = new Date()
    temp.setTime(date)
    let day = this.format_date(temp)
    return day
  };

  //获取当前月份
  Vue.prototype.get_curMonth = function () {
    //获取
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值