简体   繁体   English

Utilities.formatDate() 返回月份为 0

[英]Utilities.formatDate() returning month as 0

row[0] is a date formatted such that is shows as 8/16/22 in google sheets. row[0] 是一个日期格式,在谷歌表格中显示为 8/16/22。

And for the code,对于代码,

var date = Utilities.formatDate(new Date(row[0]), SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(), "m/d/yy");
SpreadsheetApp.getUi().alert(date);

I expected the output of 8/16/22 but instead get the following:我预计 22 年 8 月 16 日的 output 但得到以下结果:

实际输出

My end goal is to have this date be pasted into a google doc template using the following line:我的最终目标是使用以下行将此日期粘贴到谷歌文档模板中:

body.replaceText('{{date}}', date);

And here is the output of just SpreadsheetApp.getUi().alert(new Date(row[0]));这是SpreadsheetApp.getUi().alert(new Date(row[0]));

无格式输出

As written in official documentation :正如官方文档中所写:

m is minute, use M instead. m是分钟,请改用M

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Utilities.formatDate,2017年12月31日为1秒= 1年 - one second = 1 year for 12/31/2017 using Utilities.formatDate Google Apps脚本日期格式问题(Utilities.formatDate) - Google Apps Script date format issue (Utilities.formatDate) Utilities.formatDate 在第 7 天而不是第 1 天开始一​​周 - Utilities.formatDate starts the week on day 7 instead of day 1 谷歌脚本“Utilities.formatDate”对时区参数不做任何事情 - Google Scripts "Utilities.formatDate" does nothing with the time zone parameter Google App Script Utilities.formatDate(new Date()今天增加了几天 - Google App Script Utilities.formatDate(new Date() adding days to today Google Apps脚本中的Utilities.formatDate()输出以前的日期(例如,输入25.05.2015->输出24.05.2015) - Utilities.formatDate() in Google Apps Script outputs previous date (e.g. input 25.05.2015 -> output 24.05.2015) 使用 new Date() 和 Utilities.formatDate 进行日期操作会抛出意外结果 - Date Manipulation using new Date() & Utilities.formatDate throw Unexpected Results 为什么它在本月返回未定义。 JS日期 - Why is it returning undefined for the month. JS date 使用 Angular 格式日期 - Using Angular formatDate g:服务中的formatDate替代方案 - g:formatDate alternative in a service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM