Formatting of date and time in Google Script for google calendar -


One question I raised above for another question (): I now have a date in format dd.mm.yyy and In my Google Script, the start time and end time (on a European 24-hour scale) as a variable, what I finally want to do is, there is an event with these dates in my Google Calendar, I know how an event has happened, but How do I get my date & amp; Time variables for this work? I do not know it's relevant, but I live in the Central European Time Zone.

Thank you very much in advance

Best, Phil

Once you have different values ​​(hours, minutes and dates) with these values, it becomes quite easy to make the date objects.

The calendar event requires 2 full date objects, for start date / time and for an expiration date / time.

The code can be written in different ways, below is an example that helps you to see better what happens.

  function myFunction () {var timeString = 'Event 2014 18:30 - 23:00' in Cologne 25.10; // Your data looks like this kind of date = timeline Match (/ ([\ de] + \. [\ D] + \. [\ D] +) / g). ToString () the division ('.'); Shrink into an array of DD, mm, yyyy var time = timeString.match (/ ((([[0-1] [[0-9]). ([2] [0-3]) :) ([ 0-5] [0- 9]) / g); // This start and end time is Logger.log ('date =' + date + 'time =' + time); // Logger start = new date ( Check the values ​​in the date [2], date [1] -1, date [0]); Create start date objects to get started. Setter (time [0] .split (':') [0]) Problems starting at the beginning of the beginning of the hour. Problems (time [0] .split (':') [1]) // set minutes end = new date (date [2], date [1] -1, date [0]); // End.setHours (':') [0]); end.setMinutes (':' time [1] (.split) [1]); logger.log ('\' Startstart = '+ start +' \ nend = '+ end); // test end result}  

log result:


Comments