[英]How to convert primitive value to Date object in GAS
我以前使用new Date().valueOf()
通過谷歌應用程序腳本將日期對象轉換為原始值。
原始值是 1.626139723E12。
我想將原始值轉換回人類可讀的日期對象。
我試過:B4 => 1.626139723E12
B4.Gettime => 未定義
B4.toString => 1.626139723E12
新日期(B4) => 無效日期
B4.toLocaleString() => 1.626139723E12
B4.toUTCString() => 不是函數
Utilities.formatDate(B4, "GMT", "MM/dd/yyyy-HH:mm:ss") => 異常:參數 (String,String,String) 與 Utilities.formatDate 的方法簽名不匹配
根據 Copper 的評論,我也嘗試:
var scriptProperties = PropertiesService.getScriptProperties();
var PropName = "Last time"
var LastForwardTime = scriptProperties.getProperty(PropName);
function test(){
Logger.log(LastForwardTime);
const dt = new Date(LastForwardTime);
Logger.log(dt)
}
日志如下:
1:38:09 PM Notice Execution started
1:38:11 PM Info 1.626139723E12
1:38:11 PM Info Thu Jan 01 08:00:00 GMT+08:00 1970
1:38:09 PM Notice Execution completed
它工作不正常。
那么有沒有一種方法可以將原始值轉換回谷歌應用程序腳本中的 Date 對象。
只需使用 Date 構造const dt = new Date(value);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.