Dominique Charlebois Dominique Charlebois - 3 months ago 30x
Javascript Question

Convert Date Value to Timestamp - Post Request - Ember.js

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
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.


all the code sample I've seen to fix these problems, require the date in the function.


var myDate="26-02-2012";
var newDate=myDate[1]+"/"+myDate[0]+"/"+myDate[2];
alert(new Date(newDate).getTime());


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;


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.


So I finally figured it out with some help from friends. I created an action that took the formatted date from date-picker and transformed it into UNIX time in milliseconds.

actions: {
          var fromDate = moment(from).valueOf(); 

**I've changed it this way due to issues displaying the date with the bootstrap-datepicker when you use the changeDate.