js add timestamp clg

Solutions on MaxInterview for js add timestamp clg by the best coders in the world

showing results for - "js add timestamp clg"
Salomé
12 Oct 2017
1var log = console.log;
2
3console.log = function () {
4    var first_parameter = arguments[0];
5    var other_parameters = Array.prototype.slice.call(arguments, 1);
6
7    function formatConsoleDate (date) {
8        var hour = date.getHours();
9        var minutes = date.getMinutes();
10        var seconds = date.getSeconds();
11        var milliseconds = date.getMilliseconds();
12
13        return '[' +
14               ((hour < 10) ? '0' + hour: hour) +
15               ':' +
16               ((minutes < 10) ? '0' + minutes: minutes) +
17               ':' +
18               ((seconds < 10) ? '0' + seconds: seconds) +
19               '.' +
20               ('00' + milliseconds).slice(-3) +
21               '] ';
22    }
23
24    log.apply(console, [formatConsoleDate(new Date()) + first_parameter].concat(other_parameters));
25};
26