Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date string conversion to unix timestamp in JavaScript / jQuery

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?

like image 593
sozhen Avatar asked Jul 16 '12 17:07

sozhen


People also ask

How do you create a timestamp in JavaScript?

In JavaScript, in order to get the current timestamp, you can use Date. now() . It's important to note that Date. now() will return the number of milliseconds since January, 1 1970 UTC.

Which function is used to return the Unix timestamp of date?

UNIX_TIMESTAMP() : This function in MySQL helps to return a Unix timestamp. We can define a Unix timestamp as the number of seconds that have passed since '1970-01-01 00:00:00'UTC. Even if you pass the current date/time or another specified date/time, the function will return a Unix timestamp based on that.


1 Answers

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 
like image 57
Grzegorz Kaczan Avatar answered Oct 14 '22 11:10

Grzegorz Kaczan