取得指令碼的時區。新指令碼預設為擁有者的時區,但您可以按一下指令碼編輯器中的「File」>「Project properties」,變更指令碼的時區。請注意,試算表有不同的時區,您可以按一下 Google 試算表中的「檔案」>「試算表設定」來變更時區。試算表時區與指令碼時區不同,經常會導致指令碼錯誤。
// Log the time zone of the script.consttimeZone=Session.getScriptTimeZone();Logger.log(timeZone);
// Log the temporary key of the person running the script.Logger.log(Session.getTemporaryActiveUserKey());
回攻員
String:臨時有效使用者鍵
已淘汰的方法
getTimeZone()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
取得指令碼的時區。新指令碼預設為擁有者的時區,但您可以按一下指令碼編輯器中的「File」>「Project properties」,變更指令碼的時區。請注意,試算表有不同的時區,您可以按一下 Google 試算表中的「檔案」>「試算表設定」來變更時區。試算表時區與指令碼時區不同,經常會導致指令碼錯誤。
// Log the time zone of the script.consttimeZone=Session.getTimeZone();Logger.log(timeZone);
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThe \u003ccode\u003eSession\u003c/code\u003e class in Apps Script allows you to access information about the current user and the script's environment, such as the user's locale and the script's time zone.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve information about the active user, effective user, script time zone, and a temporary active user key using methods like \u003ccode\u003egetActiveUser()\u003c/code\u003e, \u003ccode\u003egetEffectiveUser()\u003c/code\u003e, \u003ccode\u003egetScriptTimeZone()\u003c/code\u003e, and \u003ccode\u003egetTemporaryActiveUserKey()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eSome methods like \u003ccode\u003egetTimeZone()\u003c/code\u003e and \u003ccode\u003egetUser()\u003c/code\u003e are deprecated and should be replaced with their updated counterparts such as \u003ccode\u003egetScriptTimeZone()\u003c/code\u003e and \u003ccode\u003egetActiveUser()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile the user's email address can be accessed in certain circumstances using \u003ccode\u003egetActiveUser().getEmail()\u003c/code\u003e or \u003ccode\u003egetEffectiveUser().getEmail()\u003c/code\u003e, it may not be available if security policies restrict access or in contexts without explicit user authorization.\u003c/p\u003e\n"],["\u003cp\u003eAccessing user information may require specific authorization scopes, like \u003ccode\u003ehttps://www.googleapis.com/auth/userinfo.email\u003c/code\u003e, to be granted to the script.\u003c/p\u003e\n"]]],[],null,[]]