javascript - combine date and time into a single datetime -
i have date , time control, concatenate
var startdate = jquery('#startdatepicker').find("input").val(); var starttime = jquery('#starttimepicker').find("input").val();
i have var field has data below:
var targettime = new date().setminutes(-5).valueof();
startdatepicker has value : 02/06/2017
starttimepicker, currenttime has value : 05:17 am
targettime has value as: 1486374940591
i want concatenate startdate , starttime in format of targettime. how concatenate start date , start time? thanks
pass date , time function. return date object. use gettime() on desired result. codepen example.
function getasdate(day, time) { var hours = number(time.match(/^(\d+)/)[1]); var minutes = number(time.match(/:(\d+)/)[1]); var ampm = time.match(/\s(.*)$/)[1]; if(ampm == "pm" && hours<12) hours = hours+12; if(ampm == "am" && hours==12) hours = hours-12; var shours = hours.tostring(); var sminutes = minutes.tostring(); if(hours<10) shours = "0" + shours; if(minutes<10) sminutes = "0" + sminutes; time = shours + ":" + sminutes + ":00"; var d = new date(day); var n = d.toisostring().substring(0,10); var newdate = new date(n+"t"+time); return newdate; }
Comments
Post a Comment