Date string conversion to unix timestamp in JavaScript / jQuery

sozhen picture sozhen · Jul 16, 2012 · Viewed 80k times · Source

I have date string in this format:

2009-07-15 00:00:00 - 2009-07-15 08:16:23

Could anyone help me to tweak the date string to unix timestamp into something like this:

1247634000 - 1247663783

I am using GMT-5 Timezone.

What JavaScript or jQuery techniques could be used?

Answer

Grzegorz Kaczan picture Grzegorz Kaczan · Jul 16, 2012

I strongly advise you to use Moment Date lib when working with dates in js. It's really light and awesome.

var timeStamp = ( moment('2009-07-15 00:00:00').unix() )*1000