Last active
August 13, 2020 07:14
-
-
Save phplaw/1c148b91dfe447a30ec642054da7d296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // pretty log object | |
| var x = [{a:1}, {a:2}, {a:3}]; | |
| var log = console.log; | |
| log(x.unshift({a:4}, {a:5})); | |
| log(JSON.stringify(x, null, 2)); | |
| // to mysql datetime format | |
| function twoDigits(d) { | |
| return d.toString().padStart(2,0); | |
| /* | |
| if(0 <= d && d < 10) return "0" + d.toString(); | |
| if(-10 < d && d < 0) return "-0" + (-1*d).toString(); | |
| return d.toString();*/ | |
| } | |
| Date.prototype.toMysqlFormat = function() { | |
| return this.getFullYear() + "-" + twoDigits(1 + this.getMonth()) + "-" + twoDigits(this.getDate()) + " " + twoDigits(this.getHours()) + ":" + twoDigits(this.getMinutes()) + ":" + twoDigits(this.getSeconds()); | |
| }; | |
| console.log(new Date().toMysqlFormat()); | |
| // new Date().toMysqlFormat() or | |
| // new Date(2014,12,14).toMysqlFormat() or whatever. | |
| // end to mysql datetime format | |
| // iput date to mysql date | |
| var x = "22/06/2020".split('/').reverse().join('-'); | |
| console.log(x); | |
| // 30 minutes from now | |
| let thirtyMinutes = 30 * 60 * 1000; // convert 30 minutes to milliseconds | |
| let date1 = new Date(); | |
| let date2 = new Date(date1.getTime() + thirtyMinutes); | |
| console.log(date1); | |
| console.log(date2); | |
| function addMinute(minutes) { | |
| var dt = new Date(); | |
| dt.setMinutes( dt.getMinutes() + minutes ); | |
| return dt; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
polyfill for Object.values