在 Google Apps 脚本中,如何获取没有指数的毫秒值?

Ale*_*gli 3 google-apps-script

我正在尝试在谷歌应用程序脚本中使用 UrlFetch 向网络服务发送毫秒时间戳。我的网络服务期望时间格式为 1433563200021,但 google 应用程序脚本不断将其转换为指数为 1.433563200021E12 的字符串,即使我调用 Number(startDate.getTime()) 也是如此。如何让谷歌应用程序脚本仅将数值存储在变量中?

Ale*_*gli 5

我发现你可以调用该toFixed(0)方法来强制它删除指数格式。例如

var start = new Date();
var startTime = Number(start.getTime()).toFixed(0);
Run Code Online (Sandbox Code Playgroud)