admin管理员组文章数量:1404950
I have a time format I get from Google Calendar events, and i need to convert it to be readable in Google Timeline Charts (using Google Apps Scripts). I would've thought it would use the same format but it doesn't.
I need this: "Tue Oct 01 11:30:00 GMT+10:00 2019"
To resemble this: "new Date(2019, 10, 01, 11, 30)"
Here is what I have so far, but the problem is Apps Script can't find 'DateTime' ("ReferenceError: "DateTime" is not defined.")
Any thoughts on how to load DateTime or another method to convert?
var result = DateTime.ParseExact(
"Tue Oct 01 11:30:00 GMT+10:00 2019",
"ddd mmm dd hh:mm:00 \\\\\\\\\ yyyy+",
CultureInfo.InvariantCulture)
.ToString("yyyy+, mm, dd, hh, mm, ss");
Logger.log(result);
I have a time format I get from Google Calendar events, and i need to convert it to be readable in Google Timeline Charts (using Google Apps Scripts). I would've thought it would use the same format but it doesn't.
I need this: "Tue Oct 01 11:30:00 GMT+10:00 2019"
To resemble this: "new Date(2019, 10, 01, 11, 30)"
Here is what I have so far, but the problem is Apps Script can't find 'DateTime' ("ReferenceError: "DateTime" is not defined.")
Any thoughts on how to load DateTime or another method to convert?
var result = DateTime.ParseExact(
"Tue Oct 01 11:30:00 GMT+10:00 2019",
"ddd mmm dd hh:mm:00 \\\\\\\\\ yyyy+",
CultureInfo.InvariantCulture)
.ToString("yyyy+, mm, dd, hh, mm, ss");
Logger.log(result);
Share
asked Sep 25, 2019 at 2:28
JackNapierJackNapier
4482 gold badges6 silver badges19 bronze badges
1
-
1
In ECMAScript, months are zero indexed so for October you want
new Date(2019, 9, 01, 11, 30)
. ;-) – RobG Commented Sep 25, 2019 at 4:21
1 Answer
Reset to default 2On Google Apps Script, to format a date as a string use Utilities.formatDate(...)
DateTime.ParseExact(...)
isn't standard JavaScript. You could declare it before using it, or just use the above suggestion.
本文标签: dateConvert DateTime string using Javascript and Apps ScriptStack Overflow
版权声明:本文标题:date - Convert DateTime string using Javascript and Apps Script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744856775a2628821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论