Vue new Date()时区问题

最近想自己搞点东西,在夜里要输出时间时发现总是输出的昨天的时间,一查发现是New Date()使用的是UTC时间,跟北京时间有时差,所以可以采用如下方法:

        const currentDate = new Date();
        const formattedDate = `${currentDate.getFullYear()}-${String(currentDate.getMonth() + 1).padStart(2, '0')}-${String(currentDate.getDate()).padStart(2, '0')}`;
        console.log("date", formattedDate);

问题得到了解决