uniapp获取日期

发布时间:2024年01月05日

1.使用new Date()方法获取系统今天的日期,显示格式为:2023-10-28

<template>
    <view class="content">
        {{date}}
    </view>
</template>
<script>
    export default {
        data() {
            return {
                date: new Date().toISOString().slice(0, 10),
            }
        },
        onLoad() {
        },
        methods: {}
    }
</script>
<style>
</style>

2.单独获取年、月、日

// 获取当前日期
let currentDate = new Date();
 
// 获取月份
let month = currentDate.getMonth() + 1;
 
// 获取日
let day = currentDate.getDate();
 
// 打印月日
console.log(`当前月日:${month}月${day}日`);

3.获取当前星期

// 获取当前日期
let currentDate = new Date();
 
// 星期数组
let weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
 
// 获取星期
let weekDay = currentDate.getDay();
 
// 打印星期
console.log(`当前星期:${weekDays[weekDay]}`);

?

文章来源:https://blog.csdn.net/m0_71966801/article/details/135398221
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。