Google脚本从字符串不正确的日期转换?

时间:2018-10-29 06:31:08

标签: google-apps-script google-sheets

我的Google脚本中的以下代码:

var checkin_date = new Date(customer.checkin); //customer.checkin format DD/MM/YYYY
Logger.log("%s", customer.checkin);
Logger.log("%s", checkin_date);

给我

[18-10-28 23:28:06:662 PDT] 26/10/2018
[18-10-28 23:28:06:662 PDT] Mon Feb 10 00:00:00 GMT+05:30 2020

哪个错了,为什么?

1 个答案:

答案 0 :(得分:1)

var customer="26/10/2018"
var dateArray=customer.split('/'); //[26,10,2018]

//new Date(year, month-1, day)
var checkin_date=new Date(dateArray[2],dateArray[1]-1,dateArray[0]);
checkin_date=Utilities.formatDate(new Date(checkin_date), Session.getScriptTimeZone(),         "dd/MM/yyyy");
Logger.log(checkin_date)

希望这会有所帮助