Skip to content

Instantly share code, notes, and snippets.

@yoshiko-pg
Created March 12, 2014 08:46
Show Gist options
  • Save yoshiko-pg/9503158 to your computer and use it in GitHub Desktop.
Save yoshiko-pg/9503158 to your computer and use it in GitHub Desktop.
Googleカレンダーへ予定追加するリンクURL生成コード
var url = (function(){
var getUTC = function(date_str){
var date = new Date(date_str);
return date.getUTCFullYear() +
zerofill(date.getUTCMonth()+1) +
zerofill(date.getUTCDate()) +
'T' +
zerofill(date.getUTCHours()) +
zerofill(date.getUTCMinutes()) +
zerofill(date.getUTCSeconds()) +
'Z';
};
var zerofill = function(num){
return ('0'+num).slice(-2);
}
return 'http://www.google.com/calendar/event?' +
'action=' + 'TEMPLATE' +
'&text=' + encodeURIComponent('予定タイトル') +
'&details=' + encodeURIComponent('予定の説明') +
'&location='+ encodeURIComponent('場所') +
'&dates=' + getUTC('2014-01-31T19:30:00+09:00') + '/' + getUTC('2014-01-31T21:30:00+09:00') +
'&trp=' + 'false' +
'&sprop=' + encodeURIComponent('リンク設置元のURL') +
'&sprop=' + 'name:' + encodeURIComponent('リンク設置元のサービス名');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment