且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建一个返回Google表格中日期的函数

更新时间:2023-11-23 21:46:04

问题:



getMonth 返回0到11的月份,其中0代表一月,11代表十二月。 getDay 返回星期几0-6,其中0代表星期日,6代表星期六。因此,日志:

Issue:

getMonth returns the month from 0-11, where 0 represents January and 11 represents December. getDay returns Day of the week 0-6, where 0 represents Sunday and 6 represents Saturday. So, the log:

returnDate(1): 11.0 / 2.0 / 2020.0

是正确的并表示

returnDate(1): Dec / Tue / 2020.0

Tue Dec 01 2020 00:00:00 GMT-0500 (Eastern Standard Time) 



解决方案:



使用 Intl

console.info(new Intl.DateTimeFormat().format(returnDate))

console.log("returnDate(1):", returnDate.getMonth()+1, "/" , returnDate.getDate(), "/", returnDate.getFullYear());//Note Date vs Day and "+1"