使用应用脚本和Google日历我得到events with same name:
function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("calendar");
var scope = "https://www.googleapis.com/auth/calendar";
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
}
function beginEnd(calId, eventName){
authorize();
var key = "...";
var query = encodeURIComponent(eventName);
calId = encodeURIComponent(calId);
var params = {
method: "get",
oAuthServiceName: "calendar",
oAuthUseToken: "always",
};
var url = "https://www.googleapis.com/calendar/v3/calendars/"+
calId+"/events?q=" + query + "&key=" + key;
var request = UrlFetchApp.fetch(url, params);
var response = Utilities.jsonParse(request.getContentText());
var items = response.items;
for ( i = 0 ; i < items.length ; i++){
var start = (items[i].start.dateTime);
var end = (items[i].end.dateTime);
Logger.log( [start,end]);
}
}
但是,当我尝试将开始转换为新日期时:
var start = (items[i].start.dateTime);
Logger.log(start);
Logger.log( new Date(start) );
我得到了
2013-01-21T15:00:00-03:00
Wed Dec 31 16:00:00 PST 1969
为什么?
答案 0 :(得分:3)
似乎日期定义不喜欢连字符......
就像这样,即使我确定可以找到更好的解决方案(我不是正则表达式专家; - )
Logger.log(new Date('2013-01-21T15:00:00-03:00'.replace(/-/g,'/').replace(/[A-Z]/,' ').substr(0,19)))