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

一些时间方法

1.禁用之前的时间

<el-date-picker
  :picker-options="disableBeforePicker"

disableBeforePicker: {
  disabledDate(time) {
    return time.getTime() < Date.now() - 8.64e7;
  },
},

2.选择开始时间之后,结束时间为开始时间之后的120分钟,他们的格式是yyyy-MM-dd HH:mm:ss

dataChange(value){
  if(value&&!this.endTime){
    const startDate = new Date(this.startTime.replace(/-/g, '/'));
    startDate.setMinutes(startDate.getMinutes() + 120);
    const year = startDate.getFullYear();
    const month = String(startDate.getMonth() + 1).padStart(2, '0');
    const day = String(startDate.getDate()).padStart(2, '0');
    const hours = String(startDate.getHours()).padStart(2, '0');
    const minutes = String(startDate.getMinutes()).padStart(2, '0');
    const seconds = String(startDate.getSeconds()).padStart(2, '0');
    this.endTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  }
},

3.比较大小,获取当前时间

time(value, time) {
  const valueDate = new Date(value); // 将 value 转换为 Date 对象
  const timeDate = new Date(time); // 将 time 转换为 Date 对象
  return valueDate > timeDate; // 比较时间戳
},
isDate(value, time) {
  const valueDate = new Date(value); // 将 value 转换为 Date 对象
  const timeDate = new Date(time); // 将 time 转换为 Date 对象
  return valueDate >= timeDate; // 比较时间戳
},
getCurrentTime() {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,需要 +1
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
},

http://www.dtcms.com/a/31253.html

相关文章:

  • python入门 介绍及变量的使用
  • 低代码与开发框架的一些整合[2]
  • Error: error:0308010C:digital envelope routines::unsupported
  • My Metronome for Mac v1.4.2 我的节拍器 支持M、Intel芯片
  • 【工具篇】【深度解析 DeepAI 工具:开启 AI 应用新体验】
  • 机器翻译中的编码器、自注意和解码器
  • c语言中offseto宏
  • 单片机 code RO-data RW-data ZI-data以及OTA学习
  • 在PyTorch中使用插值法来优化卷积神经网络(CNN)所需硬件资源
  • Spring面试题2
  • gitlab 解决双重认证无法登录remote: HTTP Basic: Access denied.
  • webmin配置终端显示样式,模仿UbuntuDesktop终端
  • 25年HVV关于0day的面试题
  • Elasticsearch Open Inference API 增加了对 Jina AI 嵌入和 Rerank 模型的支持
  • 改进收敛因子和比例权重的灰狼优化算法【期刊论文完美复现】(Matlab代码实现)
  • Python爬虫实战:获取笔趣阁小说信息,并做数据分析
  • 科普:你的笔记本电脑中有三个IP:127.0.0.1、无线网 IP 和局域网 IP;两个域名:localhost和host.docker.internal
  • 【Linux】进程优先级
  • 【小白学AI系列】NLP 核心知识点(八)多头自注意力机制
  • js版本ES6、ES7、ES8、ES9、ES10、ES11、ES12、ES13、ES14[2023]新特性
  • 【什么是双亲委派?】
  • MySQL数据库(3)—— 表操作
  • DeepSeek与ChatGPT:AI语言模型的全面对决与开发者洞察
  • uniapp h5端和app端 使用 turn.js
  • 基于大语言模型的推荐系统(1)
  • 数据库索引:优点、缺点及常见类型
  • 鸿蒙-自定义布局-实现一个可限制行数的-Flex
  • MySQL优化
  • Pandas库:(二)数组对象的索引
  • Python 高级特性-生成器