Google脚本格式日期 [英] Google Script formatDate

查看:84
本文介绍了Google脚本格式日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道它如何工作Utilities.formatDate().我有剧本:

var A=new Date();
var B=Utilities.formatDate( A, SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(), "YY.MM.dd HH:mm");

这已经工作了几个月了,但是今天(12月31日)出现了问题... A = 2019年12月31日星期二15:24:18 GMT + 0100(CET) B ="2020.12.31 15:24" 这是虫子吗?如何修复错误? 我尝试昨天的日期:

var A=new Date(new Date()-(1 * 24 * 60 * 60 * 1000));

但formatDate返回:"20.12.30 15:24"

解决方案

尝试将此"YY.MM.dd HH:mm"更改为"yy.MM.dd HH:mm"

function tdate() {
  var A=new Date(new Date()-(1 * 24 * 60 * 60 * 1000));
  Logger.log(Utilities.formatDate(A,Session.getScriptTimeZone(),"yy.MM.dd HH:mm:ss"));
  //[19-12-31 13:44:34:975 MST] 19.12.30 13:44:34
  Logger.log(Utilities.formatDate(A,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"yy.MM.dd HH:mm:ss"));
  //[19-12-31 13:51:07:677 MST] 19.12.30 13:51:07
  Logger.log(Utilities.formatDate(A,Session.getScriptTimeZone(),"YY.MM.dd HH:mm:ss"));
  //[19-12-31 13:44:34:976 MST] 20.12.30 13:44:34
  Logger.log(Utilities.formatDate(A,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"YY.MM.dd HH:mm:ss"));
  //[19-12-31 13:51:07:678 MST] 20.12.30 13:51:07

}

简单日期格式

I don't understand how does it work Utilities.formatDate(). I have script:

var A=new Date();
var B=Utilities.formatDate( A, SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone(), "YY.MM.dd HH:mm");

This has been working for months, but today (dec 31.) is problem... A=Tue Dec 31 2019 15:24:18 GMT+0100 (CET) B="2020.12.31 15:24" This is bug? How to fix a bug? I try yesterday date:

var A=new Date(new Date()-(1 * 24 * 60 * 60 * 1000));

but formatDate return: "20.12.30 15:24"

解决方案

Try changing this "YY.MM.dd HH:mm" to "yy.MM.dd HH:mm"

function tdate() {
  var A=new Date(new Date()-(1 * 24 * 60 * 60 * 1000));
  Logger.log(Utilities.formatDate(A,Session.getScriptTimeZone(),"yy.MM.dd HH:mm:ss"));
  //[19-12-31 13:44:34:975 MST] 19.12.30 13:44:34
  Logger.log(Utilities.formatDate(A,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"yy.MM.dd HH:mm:ss"));
  //[19-12-31 13:51:07:677 MST] 19.12.30 13:51:07
  Logger.log(Utilities.formatDate(A,Session.getScriptTimeZone(),"YY.MM.dd HH:mm:ss"));
  //[19-12-31 13:44:34:976 MST] 20.12.30 13:44:34
  Logger.log(Utilities.formatDate(A,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"YY.MM.dd HH:mm:ss"));
  //[19-12-31 13:51:07:678 MST] 20.12.30 13:51:07

}

Simple Date Format

这篇关于Google脚本格式日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆