这是我在ejs文件中的代码:
<select class="form-control track-change input-lg" data-track="deadline" name="Deadline" id="Deadline" placeholder="Deadline">
<option value="0" class="task-option project-option default-option" selected="selected" style="display: block;">No deadline</option>
<option value="12" class="task-option" >12 Hours</option>
<option value="24" class="task-option project-option" style="display: block;">24 Hours</option>
<option value="48" class="task-option">2 Days</option>
<option value="72" class="task-option project-option" style="display: block;">3 Days</option>
<option value="168" class="task-option project-option" style="display: block;">1 Week</option>
<option value="336" class="project-option" style="display: none;">2 Weeks</option>
<option value="504" class="project-option" style="display: none;">3 Weeks</option>
<option value="731" class="project-option" style="display: none;">1 Month</option>
</select>
当用户选择12小时时,我需要在MySQL中保存日期+12小时,如果选择2天,我需要保存日期+ 2天后,等等。
如何使用nodejs或ejs(jade)或javascript进行操作?我只需要日期代码而不是sql查询...请帮忙吗?
答案 0 :(得分:0)
假设您每次选择该选项都可以调用函数,则可以执行此操作
function deadlineChanged(hours){
let newTime = new Date(new Date().getTime() + (hours * 60 * 60 * 1000));
///do whatever you want to do with the new time
}
如果要将其转换为mysql字符串,可以使用此函数
function formatdate(date) {
if (date instanceof Date) {
var month = date.getMonth() + 1;
var day = date.getDate();
var year = date.getFullYear();
return year + "-" + (month >= 10 ? month : "0" + month) + "-" + (day >= 10 ? day : '0' + day);
} else {
return date;
}
}