Date from string in format javascript google apps script -


in web app user needs fill fields date , time. in date can enter date in format: d/m/yy or dd/mm/yy (unfortunately can't control how user enter it)

and can pick time drop-down list: 08:00am,8.30am, 09:00am,.... , 05:00 pm

now, trying convert time , date strings valid date object using function below, getting "date isinvalid date" output. how should proceed it?

  var timestartstring ="1970/01/01 "+ "10:00am";   var st1 =createdate("1/12/2013",timestartstring);    logger.log("date is"+st1);   function createdate(datestring,timestring)     {       var eventdate  = new date(datestring);       var eventtime  = new date(timestring)        message +="date string:"+datestring + " timestring "+timestring;        eventtime.setfullyear(eventdate.getfullyear());       eventtime.setdate(eventdate.getdate());       eventtime.setmonth(eventdate.getmonth());         return eventtime;     } 

you may want using moment.js library, makes date parsing , manipulation in javascript bit easier. more information on how use in apps script here. if date format consistent, can use custom format string parse it.

var date = moment('1970/01/01 10:00am', 'yyyy/mm/dd hh:mma').todate(); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -