9

I'm using jQuery UI datepicker with time plugin. This is how I display time on the page in datepicker itself:

21.06.2012 08:00

I'd like to convert this time to UNIX timestamp before sending to backend. How can I do this? I don't need to dispay UNIX time on the page, I only need to convert before posting. I've tried:

var d = Date.parse(value_of_datepicker);

but had no luck. It seems date should be formated in another way. Also I've tried several build-in datepicker functions, but all of them set date display view. Thanks.

1 Answer 1

17

If you use jQuery timepicker by Trent Richardson, you can do this: $("#your_datepicker").datetimepicker("getDate").getTime() / 1000

http://jsfiddle.net/d6Tky/

Remember that this function may return null if no date has been selected.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm running this, but it seems to be off by one hour early. Any updates on why this could be happening?
Problem seems to be linked with wrong time zone or daylight saving. Probably, you should check this article of Trent Richardson: trentrichardson.com/2011/03/04/timepicker-gets-time-zone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.