gpt4 book ai didi

javascript - 获取当前月份的 Google Apps 脚本(很多 IF 语句)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:09 30 4
gpt4 key购买 nike

我已经完成了一个脚本,可以在 Logger 中打印出当前月份。我认为这可以通过数组以更好的方式完成。

这是我目前所拥有的:

function myFunction() {

var date = new Date();
var mt = date.getMonth();
var currentD

if (mt === 0) {
currentD = "JAN (qty)";
}if (mt === 1) {
currentD = "FEB (qty)";
}if (mt === 2) {
currentD = "MAR (qty)";
}if (mt === 3) {
currentD = "APR (qty)";
}if (mt === 4) {
currentD = "MAJ (qty)";
}if (mt === 5) {
currentD = "JUNI (qty)";
}if (mt === 6) {
currentD = "JULY (qty)";
}if (mt === 7) {
currentD = "AUG (qty)";
}if (mt === 8) {
currentD = "SEP (qty)";
}if (mt === 9) {
currentD = "OKT (qty)";
}if (mt === 10){
currentD = "NOV (qty)";
}else if (mt === 11){
currentD = "DEC (qty)";
}

Logger.log("Current Month is: " +currentD);
}

最佳答案

有一个 Utility为此。

var currentD = Utilities.formatDate(date, Session.getScriptTimeZone(), "MMM");

关于javascript - 获取当前月份的 Google Apps 脚本(很多 IF 语句),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33343338/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com