10 examples of 'javascript date to unix' in JavaScript

Every line of 'javascript date to unix' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
8function unix (date) {
9 let d
10 if (date) {
11 d = new Date(date)
12 }
13 if (!isDate(d)) {
14 d = new Date()
15 }
16 return Math.round(d.getTime() / 1000)
17}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

127function toUnixTimestamp(date) {
128 return Math.floor(date.getTime() / 1000);
129}
31function toUnixDate(date){
32 var datea = date.split(':');
33 var d = new Date();
34 //d.setFullYear(datea[2],datea[1]-1,datea[0]);
35 d.setHours( datea[0] );
36 d.setMinutes( datea[1] );
37 d.setSeconds( 0 );
38 return Math.floor(d.getTime() / 1000);
39}
5export function dateUTCToLocal( date )
6{
7 return new Date( date.getTime( ) + TimeZoneOffset );
8}
21export function dateToUTC(timestamp) {
22 const date = new Date(timestamp * 1000);
23 return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
24 date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
25}
59function getUnixTime(date) {
60 const d = new Date(date);
61 const ts = d.getTime();
62 const MILLI = 1000;
63
64 return Math.floor(ts / MILLI);
65}
47unixMsToObject(ms) {
48 return new Date(ms);
49}
33function time_converter(UNIX_timestamp) {
34 var a = new Date(UNIX_timestamp * 1000);
35 var year = a.getFullYear();
36 var month = a.getMonth() + 1;
37 var date = a.getDate();
38 var hour = a.getHours();
39 var min = a.getMinutes();
40 var sec = a.getSeconds();
41 var time =
42 year +
43 '-' +
44 pad(month, 2) +
45 '-' +
46 pad(date, 2) +
47 ' ' +
48 pad(hour, 2) +
49 ':' +
50 pad(min, 2) +
51 ':' +
52 pad(sec, 2);
53 return time;
54}
38function toUNIX(time) {
39 return time / 1000
40}
618function timeConverter(unixtime){
619 var d = new Date(unixtime);
620 return d.toString();
621}

Related snippets