Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js 年月日

作者:夕阳下的孤影   发布日期:2026-05-07   浏览:130

// 获取当前的年月日并打印
function getYearMonthDay() {
    const now = new Date(); // 创建一个表示当前日期和时间的Date对象
    const year = now.getFullYear(); // 获取当前年份
    const month = now.getMonth() + 1; // 获取当前月份(注意:getMonth()返回的是0-11,所以需要加1)
    const day = now.getDate(); // 获取当前日期

    // 返回格式化的年月日字符串
    return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
}

console.log(getYearMonthDay()); // 输出类似 "2023-10-05"

上一篇:js date 年月日

下一篇:js 获取当月第一天

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站