当前位置: 首页 > news >正文

js 获取当前时间与前一个月时间

// 获取当前时间的毫秒数
var currentTimeMillis = new Date().getTime();// 获取前一个月的Date对象
var dateLastMonth = new Date();
dateLastMonth.setMonth(dateLastMonth.getMonth() - 1);// 获取前一个月的毫秒数
var timeMillisLastMonth = dateLastMonth.getTime();console.log("当前时间的毫秒数:", currentTimeMillis);
console.log("前一个月的毫秒数:", timeMillisLastMonth);

如果要在饿了么日期组件使用,比如默认时间为当前时间到过去一个月时间

实现代码如下

 <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始时间"style="width: 195px;" prefix-icon="none" @change="getdatePickTime"end-placeholder="结束时间">
</el-date-picker>data(){return {value1: [new Date().setMonth(new Date().getMonth() - 1), new Date()],}
}

如果需要添加快捷键

 

 <el-date-picker v-model="value1" :picker-options="pickerOptions"type="daterange" range-separator="至" start-placeholder="开始时间"style="width: 195px;" prefix-icon="none" @change="getdatePickTime"end-placeholder="结束时间">
</el-date-picker>data(){return {value1: [new Date().setMonth(new Date().getMonth() - 1), new Date()],pickerOptions: {shortcuts: [{text: '最近一周',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);picker.$emit('pick', [start, end]);}}, {text: '最近一个月',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);picker.$emit('pick', [start, end]);}}, {text: '最近三个月',onClick(picker) {const end = new Date();const start = new Date();start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);picker.$emit('pick', [start, end]);}}]},}
}

http://www.lryc.cn/news/471601.html

相关文章:

  • 深度了解flink rpc机制(四) 组件启动流程源码分析
  • C++基于opencv的视频质量检测--遮挡检测
  • 手机玩潜水员戴夫?GameViewer远程如何随时随地玩潜水员戴夫教程
  • UE5 喷射背包
  • 【Vue3】第三篇
  • c++二级指针
  • 客户端存储 — IndexedDB 实现分页查询
  • logback 如何将日志输出到文件
  • Files.newBufferedReader和Files.readAllLines
  • MySQL 数据库备份与恢复全攻略
  • Appium中的api(一)
  • 【AI辅助设计】没错!训练FLUX LoRA就这么简单!
  • Mac 下安装FastDFS
  • 人工智能的未来:重塑生活与工作的变革者
  • 【微服务】Java 对接飞书多维表格使用详解
  • 学习threejs,使用粒子实现下雪特效
  • unity3d——Time
  • 天地图实现海量聚合marker--uniapp后端详细实现
  • Bug | 项目中数据库查询问题
  • C++入门基础知识129—【关于C 库函数 - time()】
  • 大文件秒传,分片上传,断点续传
  • 多生境扩增子探秘:深度溯源与多样性解析
  • Selenium4自动化测试常用函数总结,各种场景操作实战
  • 图像生成新范式:智源推出全能视觉生成模型 OmniGen
  • 实现RPC接口的demo记录
  • Python期末题目 | 期末练习题【概念题+代码】
  • OpenCV基本操作(python开发)——(6)视频基本处理
  • 详解Java之Spring MVC篇一
  • ubuntu20.04上使用 Verdaccio 搭建 npm 私有仓库
  • Python实现办公自动化的数据可视化与报表生成