将日期/时间设置为00:00:00 [英] Set Date/Time to 00:00:00
问题描述
我有一系列日期,日期中的时间不同。
I have an array of dates with different times in the date.
例如:{4/15/13 05:00:00,03/10/13 13:00:00、02 / 10/13 02:00:00等}
Example: {4/15/13 05:00:00, 03/10/13 13:00:00, 02/10/13 02:00:00, etc.}
如果我只想将小时更改为00:00:00,那么数组将显示为:
If I wanted to change just the hour to 00:00:00 so the array would read:
{4/15/13 00:00:00,03/10/13 00:00:00,02/10/13 00: 00:00,等等。}
{4/15/13 00:00:00, 03/10/13 00:00:00, 02/10/13 00:00:00, etc.}
我该怎么做?
我尝试使用getTime( ),但我无法控制整个工作时间。任何帮助都会很棒。
谢谢!
I've tried using getTime(), but I don't have control over just the hours. Any help would be great. Thanks!
编辑:我尝试了以下循环:
I tried this loop:
for (var i = 0; i < gValues.length; i++) { // repeat loop
sheet.getRange(i + 2, 7, 1, 1).setValue(gValues[i][0].setHours(00,00,00,00));
}
但我得到的值不是期望的结果: 12/20 / 5828963 0:00:00。
But instead of the desired result, I get this value: "12/20/5828963 0:00:00" for every single cell.
推荐答案
Google Apps脚本是JavaScript,日期操作是在此处进行了解释,
Google Apps Script is JavaScript, date manipulations are explained here,
设置时间像这样:
Date.setHours(hour,min,sec,millisec)
下面是一个示例:
// 3/16/2013 17:00:00
function test(){
var x = new Date('3/16/2013 17:00:00');// x is now a date object
x.setHours(0,0,0,0); set hours to 0, min Secs and milliSecs as well
Logger.log(x);// show result
}
记录仪值: 2013年3月16日00:00:00 GMT + 01:00
这篇关于将日期/时间设置为00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!