In Javascript
new Date()
Tue Mar 18 2014 18:54:17 GMT+0000 (GMT)
Date.UTC(2014,03,18)
1397779200000
In Mysql
mysql> SELECT NOW(), UTC_TIMESTAMP();
+---------------------+---------------------+
| NOW() | UTC_TIMESTAMP() |
+---------------------+---------------------+
| 2014-03-18 18:55:04 | 2014-03-18 18:55:04 |
+---------------------+---------------------+
mysql> select UNIX_TIMESTAMP('2014-03-18') ;
+------------------------------+
| UNIX_TIMESTAMP('2014-03-18') |
+------------------------------+
| 1395118800 |
There are three differences:
Date.UTC()
interprets its arguments in UTC, whereasUNIX_TIMESTAMP()
interprets its arguments in the database session's timezone. From the update to your question it appears that this may not have had any effect as the database session's local timezone might be in UTC.Date.UTC()
returns a value in milliseconds since the UNIX epoch, whereasUNIX_TIMESTAMP()
returns a value in seconds since the UNIX epoch: so they will always differ by a factor of 1000.The month argument to
Date.UTC()
is zero-indexed, so a value of03
indicates April whereas the date literal given toUNIX_TIMESTAMP()
indicates March.References are cited below.
JavaScript
As documented under
Date.UTC()
(emphasis added):Also, as documented under
TimeClip()
(emphasis added):Also, as documented under Month Number:
MySQL
As documented under
UNIX_TIMESTAMP(date)
(emphasis added):