1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 16:35:06 +00:00

LibJS: Add String.prototype.pad{Start,End}()

This commit is contained in:
Linus Groh 2020-04-10 15:22:58 +01:00 committed by Andreas Kling
parent 7636dee2cb
commit 31505dde7e
5 changed files with 107 additions and 23 deletions

View file

@ -1,29 +1,14 @@
var now = Date.now();
console.log("Unix timestamp: " + now / 1000);
// FIXME: We need String.prototype.padStart() :^)
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth() + 1;
if (month < 10)
month = "0" + month;
var day = d.getDate();
if (day < 10)
day = "0" + day;
var hours = d.getHours();
if (hours < 10)
hours = "0" + hours;
var minutes = d.getMinutes();
if (minutes < 10)
minutes = "0" + minutes;
var seconds = d.getSeconds();
if (seconds < 10)
seconds = "0" + seconds;
var milliseconds = d.getMilliseconds();
if (milliseconds < 10) {
milliseconds = "00" + milliseconds;
} else if (milliseconds < 100) {
milliseconds = "0" + milliseconds;
}
var month = (d.getMonth() + 1).toString().padStart(2, "0");
var day = d.getDate().toString().padStart(2, "0");
var hours = d.getHours().toString().padStart(2, "0");
var minutes = d.getMinutes().toString().padStart(2, "0");
var seconds = d.getSeconds().toString().padStart(2, "0");
var milliseconds = d.getMilliseconds().toString().padStart(3, "0");
console.log("Date: " + year + "-" + month + "-" + day);
console.log("Time: " + hours + ":" + minutes + ":" + seconds + "." + milliseconds);