{"id":4123,"date":"2017-03-02T02:03:30","date_gmt":"2017-03-02T07:03:30","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=4123"},"modified":"2021-12-08T12:25:27","modified_gmt":"2021-12-08T17:25:27","slug":"javascript-unix-timestamp","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/javascript-unix-timestamp\/","title":{"rendered":"Here are Three Subtle Ways to get a Unix Timestamp in JavaScript"},"content":{"rendered":"\n
Did you know you can “easily<\/em>” get a Unix-like timestamp using JavaScript<\/a> in more than just one way? Everyone has their own reasons as to why they would want to do this, but hey! We are not Judging.<\/p>\n\n\n\n For those who are lost at this point, a Unix<\/a> timestamp which is also known as POSIX time or epoch time is a system for describing instants in time, or so says Wikipedia<\/a>. It is the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.<\/p>\n\n\n\n This system is widely used on Unix-like operating systems that is why is commonly called a Unix timestamp. It is also important to note that this system does not factor in leap seconds and therefore is not a true representation of UTC.<\/p>\n\n\n\n To print the time stamp on Unix-like operating systems you can simply type this date +%s in the command line. Now let us see how we can do this in JavaScript as we restrict this to Three examples.<\/p>\n\n\n\n How to get the Unix Timestamp in JavaScript<\/p>\n\n\n\n Method 1:<\/strong> If you call:<\/p>\n\n\n\n You get a formatted date representation that looks similar to this:<\/p>\n\n\n\nnew Date();<\/code><\/pre>\n\n\n\n