相关文章推荐
无聊的煎饼果子  ·  JSON比较:如何轻松判断数据格式是否相同? ...·  1 年前    · 
有胆有识的烤土司  ·  sqlserver中将逗号字符串分隔的值怎么 ...·  1 年前    · 
精明的显示器  ·  access vba textbox ...·  1 年前    · 
Code  ›  DateTimePicker 日期时间选择器,默认获取当前日期开发者社区
date datetimepicker
https://cloud.tencent.com/developer/article/1849247
狂野的橡皮擦
2 年前
作者头像
王小婷
0 篇文章

DateTimePicker 日期时间选择器,默认获取当前日期

前往专栏
腾讯云
备案 控制台
开发者社区
学习
实践
活动
专区
工具
TVP
文章/答案/技术大牛
写文章
社区首页 > 专栏 > 编程微刊 > 正文

DateTimePicker 日期时间选择器,默认获取当前日期

发布 于 2021-07-19 16:10:13
3.1K 0
举报

在vue里面,我们已经用到过单独的TimePicker 时间选择器和DatePicker 日期选择器了,现在需要用到一个可以同时选择年月日时分秒的插件,饿了么的文档里面就有现成可以使用的~~

在同一个选择器里选择日期和时间

DateTimePicker 由 DatePicker 和 TimePicker 派生,Picker Options 或者其他选项可以参照 DatePicker 和 TimePicker。

文档: https://element.eleme.cn/#/zh-CN/component/datetime-picker

<template>
  <div class="block">
    <span class="demonstration">默认</span>
    <el-date-picker v-model="value" type="datetime" placeholder="选择日期时间">
    </el-date-picker>
</template>
<script>
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
      value: "",
  created() {
    this.Date();
  methods: {
    //获取当前年月日
    Date() {
      const nowDate = new Date();
      const date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate(),
        hours: nowDate.getHours(),
        minutes: nowDate.getMinutes(),
        seconds: nowDate.getSeconds(),
      const newmonth = date.month > 10 ? date.month : "0" + date.month;
      const newday = date.date > 10 ? date.date : "0" + date.date;
      const newminutes = date.minutes < 10 ? "0" + date.minutes : date.minutes;
      const newseconds = date.seconds < 10 ? "0" + date.seconds : date.seconds;
      this.value =
        date.year +
        "-" +
        newmonth +
        "-" +
        newday +
        " " +
        date.hours +
        ":" +
        newminutes +
        ":" +
        newseconds;
 
推荐文章
无聊的煎饼果子  ·  JSON比较:如何轻松判断数据格式是否相同?-阿里云开发者社区
1 年前
有胆有识的烤土司  ·  sqlserver中将逗号字符串分隔的值怎么做到第一行取第一个逗号的,第二行取第二个 - CSDN文库
1 年前
精明的显示器  ·  access vba textbox enter key behavior-掘金
1 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号