vue3获取当前日期和时间
vue3获取当前时间
·
话不多说,上代码
<script setup>
var a = new Date().getTime(); //获取到当前时间戳
var b = new Date(a); //创建一个指定的日期对象
console.log(b);
console.log(nowDate(b));
function nowDate(now) {
var year = now.getFullYear(); //年份
var month = now.getMonth() + 1; //月份(0-11)
var date = now.getDate(); //天数(1到31)
var hour = now.getHours(); //小时数(0到23)
var minute = now.getMinutes(); //分钟数(0到59)
var second = now.getSeconds(); //秒数(0到59)
return (
year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
)
};
</script>
更多推荐
已为社区贡献3条内容
所有评论(0)