Files
Examples/JavaScript/web-chat/utils.js
plane000 3f74792e84 web chat
2018-07-23 10:30:37 +01:00

18 lines
475 B
JavaScript

module.exports.currenttime = function() {
let d = new Date(Date.now());
return `[${pad(d.getHours(), 2)}:${pad(d.getMinutes(), 2)}:${pad(d.getSeconds(), 2)}]`;
}
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
module.exports.sleep = function(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms);
});
}