Created
February 25, 2023 23:39
-
-
Save kkm/ee8873e5dbae012495623d0f34d4f151 to your computer and use it in GitHub Desktop.
Console.log with Date Format
This file contains 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
// Console with DATE | |
var log = console.log; | |
console.log = function () { | |
var first_parameter = arguments[0]; | |
var other_parameters = Array.prototype.slice.call(arguments, 1); | |
function formatConsoleDate(date) { | |
var hour = date.getHours(); | |
var minutes = date.getMinutes(); | |
var seconds = date.getSeconds(); | |
var milliseconds = date.getMilliseconds(); | |
return '[' + | |
((hour < 10) ? '0' + hour : hour) + | |
':' + | |
((minutes < 10) ? '0' + minutes : minutes) + | |
':' + | |
((seconds < 10) ? '0' + seconds : seconds) + | |
'.' + | |
('00' + milliseconds).slice(-3) + | |
'] '; | |
} | |
log.apply(console, [colors.blue(formatConsoleDate(new Date())) + first_parameter].concat(other_parameters)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment