1

I have a input in form like this:

<input  id="sendDate" type="date" ng-model="aN.formData.sendDate" title="Formato inválido: introducir el número de segundos" required>

When i submit the form i have the output in console, this ouput: Thu Oct 29 2015 00:00:00 GMT+0100 (CET)

How I can convert this format to milliseconds when i send the form?

I've been reading other posts and have not been of much help.

thanks!

agonzalezmc
  • 113
  • 1
  • 3
  • 13

4 Answers4

10
new Date('Thu Oct 29 2015 00:00:00 GMT+0100 (CET)').getTime()
Qi Tang
  • 1,165
  • 6
  • 17
2

That's a date - not a period of time - so you can't convert that to milliseconds ...

Do you want to convert it to a unix timestamp ? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

Or do you want to get the milliseconds from a that time ?

var today = new Date();
var milliseconds = today.getMilliseconds();

example above from - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds

G.H
  • 317
  • 1
  • 7
1
$scope.aN.formData.sendDate.getTime();
Alexander Elgin
  • 6,796
  • 4
  • 40
  • 50
0

You could try moment.js (http://momentjs.com/docs). There is an "duration" feature to get milliseconds, but there is a bunch of alternative ones you wrap a date into moment.js

Colo Ghidini
  • 658
  • 9
  • 20