简体   繁体   English

如何在JavaScript中将特定时间添加到现有日期?

[英]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 这会将特定时间转换为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/ 演示: https : //jsfiddle.net/8vfnahpn/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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