0
votes

Im using the Class DateBox with Google Apps Script. The output format looks like this:

Fri Mar 07 2014 00:00:00 GMT+0100 (CET)

I would like this date to get in to the Google Calender. But the Google Calender date format looks like this:

March 8, 2014 16:00:00 UTC

Is there any way to solve this?

The DateBox:

  grid.setWidget(2, 0, app.createLabel('Tidpunkt:'));
  grid.setWidget(2, 1, app.createDateBox().setName('tid').setId('tid'));

The Google Calendar input:

 var date = e.parameter.tid;
  var lol = e.parameter.name;
  var lolz = e.parameter.info;


var event = CalendarApp.getCalendarById('[email protected]').createEvent(lol, date);                                                                                                                          
    {description: lolz});
1
you are creating (well attempting to create...) an event with the startDate=endDate... not very useful please re-read your code and update ! where is date2 defined ?Serge insas
Other comment : since e.parameter.date is a date object you don't need to create a new instance using new Date(date), use it straight out of the box ! That said, using new Date is not an issue, it is just useless.Serge insas
I just updated now, but it failsJohn Smith
What error do you have ? is that a valid calendar ID ? have you edit rights ? did you try with my example ? please be more explicit than just "it fails"...Serge insas
About your last update : when you use createEvent() you must provide 2 dates. In my example it was createAllDayEvent() which only requires one. please read the documentation here :developers.google.com/apps-script/reference/calendar/…Serge insas

1 Answers

0
votes

The dateBox widget in UiApp returns a JavaScript date object that is directly compatible with any other service, including calendar of course.

The difference you see comes from the logger, not from the object itself and is therefor irrelevant.

here is a small code to demonstrate :

    function doGet() {
      var app = UiApp.createApplication().setTitle('test');
      var date = app.createDateBox().setName('date');
      var buttonHandler = app.createServerClickHandler('show').addCallbackElement(date);
      var button = app.createButton("test",buttonHandler); 
      app.add(date).add(button);
      return app;
    }

    function show(e) {
      var app = UiApp.getActiveApplication();
      Logger.log('value of date is '+e.parameter.date+'\ntype is '+typeof(e.parameter.date)); 
      CalendarApp.getDefaultCalendar().createAllDayEvent('test title', e.parameter.date);
      app.add(app.createLabel('event created in your default Calendar'));
      return app;
    }

enter image description here