Najam Awan
Najam Awan

Reputation: 1145

jquery datepicker value to UTC timestamp

I am using jquery datetime picker and when user selects a value i need user selection to converted into utc timestamp so i that pass that to php webservice using ajax.

Datepicker I am using shows its value in 2014/09/01 11:57 format. Please let me know how i can convert this into utc timestamp in javascript.

Before jquery datetime picker I used to have html5 datetime input elements and i was reading there values using jquery and converting them into UTC timestamp and for that i wrote custom functions. Client asked to use jquery datetime picker and now we are back with this UTC thing.

Upvotes: 1

Views: 3427

Answers (1)

Pappa
Pappa

Reputation: 1645

Date.parse("2014/09/01 11:57");

or

new Date("2014/09/01 11:57");

This will create a Date object. You can return the UTC timestamp with the Date object's getTime() or valueOf() functions.

There's a lot of excellent Javascript documentation at the Mozilla Developer Network. The docs for the Date object are here:

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

Upvotes: 1

Related Questions