【发布时间】:2014-07-01 17:36:25
【问题描述】:
我正在尝试在 focus.add_days 函数中创建一个 javascript 日期对象,以便为元素中的给定日期添加一些天数。 问题是 javascript 对象不需要字符串“Y-m-d”,那么如何在不将字符串“Y-m-d”解析成片段的情况下创建日期对象,或者是唯一的方法?
trigger = {
fecha_ini: function(){
$('input[name="fecha_ini"]').on('change',function(){
console.log('hi');
var fecha_fin = $(':input [name=fecha_fin]');
var min = $(this).val();
//here is where i pass the "Y-m-d" string as the date argument
var max = fechas.add_days(min,31*4);
fecha_fin.attr('min',min);
fecha_fin.attr('max',max);
fecha_fin.val('');
})
}
};
fechas = {
add_days: function addDays(date, days) {
//here is where i use the string "Y-m-d" to create the date object, but obviusly doesnt work
var result = new Date(date);
result.setDate(date.getDate() + days);
return result;
}
};
trigger.fecha_ini();
【问题讨论】:
-
看看moment.js
标签: javascript html date object input