【格式化日期】在Vue3中如何格式化日期

使用第三方库date-fns格式化处理日期

使用步骤:

① 安装 date-fns

npm install date-fns

② 在 Vue 组件中使用 date-fns 来格式化日期:

<script setup>
import { ref } from 'vue';
// 引入date-fns
import { format } from 'date-fns';
    const currentDate = ref(new Date());
    const formattedDate = () => {
      // 使用format格式化日期
      return format(currentDate.value, 'yyyy-MM-dd');
    };
};
</script>

在以上示例中,我们使用 format 函数从 date-fns 中导入,然后将当前日期 currentDate 格式化为 ‘yyyy-MM-dd’ 形式。你可以根据需要调整格式化字符串以满足你的需求。

相关推荐

  1. 格式化日期Vue3如何格式化日期

    2024-04-22 19:52:01       35 阅读
  2. vue 时间日期格式处理

    2024-04-22 19:52:01       22 阅读
  3. VUE】moment.js 时间日期格式化工具

    2024-04-22 19:52:01       33 阅读
  4. SpringBoot日期格式化处理

    2024-04-22 19:52:01       56 阅读
  5. VUExslx解析excel日期格式问题

    2024-04-22 19:52:01       32 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 19:52:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 19:52:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 19:52:01       87 阅读
  4. Python语言-面向对象

    2024-04-22 19:52:01       96 阅读

热门阅读

  1. random模块

    2024-04-22 19:52:01       37 阅读
  2. day6-arm

    2024-04-22 19:52:01       39 阅读
  3. go下载依赖时超时timeout

    2024-04-22 19:52:01       34 阅读
  4. Ubuntu22.04.4 - MySQL8 - 笔记

    2024-04-22 19:52:01       46 阅读
  5. 如何管理一个团队,因为有些人他不听我的话?

    2024-04-22 19:52:01       45 阅读
  6. C++实战篇(一)——自旋锁的使用

    2024-04-22 19:52:01       43 阅读
  7. pinpoint接入及接入tomcat

    2024-04-22 19:52:01       37 阅读
  8. Git的SSH密钥配置

    2024-04-22 19:52:01       40 阅读