简体   繁体   中英

How to add specific time to existing date in javascript?

I have a specific date and time value from date and time picker. I need to schedule a event on the specific date and time. How to append the time to the date like,

var date = "1/19/2017"
// and
var time = "10:04 pm"

How to add this specific time to the date so that event triggers only on the scheduled date and time?

If this is what you want. This converts specific time to ms

var dateStr = "1/19/2017";
var timeStr = "10:04 pm";

var createDate = new Date(dateStr +" "+timeStr).getTime();
alert(createDate);

Demo : https://jsfiddle.net/8vfnahpn/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM