I have a time string in the following format YYYY-MM-DD hh:mm:ss.
I would like to convert it to the equivalent of passing the date-string into the mysql unix_timestamp function using Javascript.
I tried parsing the date and passing it into the Date.UTC() function but it seems to be giving me different times then what I want. help.
If you are supplying a UTC timestamp and want seconds since 1/1/1970, then:
[…]
Edit
Revisited my original answer and didn’t like it, the following is better:
Note that the string in the OP isn’t ISO8601 compliant, but the above will work with it. If the timestamp is in the local timezone, then:
If decimal seconds should be accommodated, a little more effort is required to convert the decimal part to ms.