我创建了一个函数,该函数需要一个日期和月份数以添加到该日期并返回下一个日期。该功能似乎运行良好,我使用DEBUG进行了检查。奇怪的是,当我使用下面的代码行记录返回的日期时,
monthstoadd = 18
date1.setFullYear(2019, 6, 1);
returnDate = AddMonths(date1, monthstoadd); // my selfmade function
Logger.log("returnDate(1):", returnDate.getMonth(), "/" , returnDate.getDay(), "/", returnDate.getFullYear());
日志中的日期与调试器中的日期不匹配。有人看过吗?另外,有人知道如何获取数字的整数吗?我尝试了一下,但是得到了一些奇怪的结果。
例如:调试器将值显示为Tue Dec 01 2020 00:00:00 GMT-0500(东部标准时间),但日志将值显示为returnDate(1):11.0 / 2.0 / 2020.0
getMonth
返回0-11的月份,其中0表示1月,11表示12月。getDay
返回星期几0-6,其中0代表星期日,6代表星期六。因此,日志:
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"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句