My handlebars code is as followed.
{{bootstrap-datepicker value=from placeholder="MM/DD/YYYY"}}
Here the user picks a date from a calendar to get the from
date. This is for a form.
My problem is the format is as followed: Sun May 29 2016 00:00:00 GMT-0700 (PDT)
and the post request requires milliseconds since epoch format.
SO
all the code sample I've seen to fix these problems, require the date in the function.
example:
var myDate="26-02-2012";
myDate=myDate.split("-");
var newDate=myDate[1]+"/"+myDate[0]+"/"+myDate[2];
alert(new Date(newDate).getTime());
or
function toTimestamp(year,month,day,hour,minute,second){
var datum = new Date(Date.UTC(year,month-1,day,hour,minute,second));
return datum.getTime()/1000;
}
or
var fromFormat = moment('from').fromFormat(moment(), 'milliseconds');
but I only have the name value as it changes all the time.
I've got moment-js, date-picker and a couple other add-ons. Any resources or code snippets will be appreciated.
答案 0 :(得分:1)
所以我终于在朋友的帮助下弄明白了。
我创建了一个从date-picker
获取格式化日期的操作,并将其转换为UNIX时间(以毫秒为单位)。
actions: {
PublishForm{
var fromDate = moment(from).valueOf();
}
}
**由于使用changeDate时使用bootstrap-datepicker显示日期的问题,我已经改变了这种方式。