Skip to content

Instantly share code, notes, and snippets.

@kkm
Created February 25, 2023 23:39
Show Gist options
  • Save kkm/ee8873e5dbae012495623d0f34d4f151 to your computer and use it in GitHub Desktop.
Save kkm/ee8873e5dbae012495623d0f34d4f151 to your computer and use it in GitHub Desktop.
Console.log with Date Format
// 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