简体   繁体   English

应用程序脚本从 Date() 转换为可读的内容

[英]App Script Converting from Date() to something readable

Ok I have a Google Sheet.好的,我有一个 Google Sheet。

I'm writing App Script我正在编写应用程序脚本

This script is pulling out data in a loop about Chromebooks in our GSuite and I can convert the native Long result of device.autoUpdateExpiration by using Date(device.autoUpdateExpiration) as here:这个脚本在我们的 GSuite 中循环提取有关 Chromebook 的数据,我可以使用Date(device.autoUpdateExpiration)转换device.autoUpdateExpiration的本机 Long 结果,如下所示:

do {
    page = AdminDirectory.Chromeosdevices.list('my_customer', options);

    page.chromeosdevices.forEach(function(device) {
     devices.push([device.deviceId, device.serialNumber, device.orgUnitPath, device.annotatedUser, device.annotatedUser, device.annotatedLocation, device.annotatedAssetId, device.notes, device.model, Date(device.autoUpdateExpiration), device.macAddress, device.model]);
  });
    if (page.nextPageToken){
      options.pageToken = page.nextPageToken;
    }
  } while (page.nextPageToken); 

But when the script dumps the Chromebook info to cells, the content of Date(device.autoUpdateExpiration) is:但是当脚本将 Chromebook 信息转储到单元格时, Date(device.autoUpdateExpiration)的内容是:

Thu Feb 13 2020 15:10:35 GMT+0000 (Greenwich Mean Time) 2020 年 2 月 13 日星期四 15:10:35 GMT+0000(格林威治标准时间)

Two questions:两个问题:

  1. Why isn't this giving me the actual date when the updates expire?为什么这不给我更新到期的实际日期?

  2. How do I convert this to an easy dd/mm/yyyy output?如何将其转换为简单的 dd/mm/yyyy 输出?

您可以使用new Date(device.autoUpdateExpiration).toLocaleDateString()

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM