<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>
vue获取当前时间戳
最新推荐文章于 2025-09-10 10:00:49 发布
文章展示了如何使用JavaScript获取并格式化当前日期时间,包括年月日时分秒。通过`nowDate`函数演示了如何构造特定日期对象并展示其详细信息。
652

被折叠的 条评论
为什么被折叠?



