summaryrefslogtreecommitdiff
path: root/Base/home/anon
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-10 15:22:58 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-10 16:37:04 +0200
commit31505dde7ec5e8077a5a72e7e50d4e5d7203432d (patch)
tree3c192b7eb1cac3fd1a1b64998535ee759c012d29 /Base/home/anon
parent7636dee2cb64aa81b99df9aa69f0e9b3c19db1b9 (diff)
downloadserenity-31505dde7ec5e8077a5a72e7e50d4e5d7203432d.zip
LibJS: Add String.prototype.pad{Start,End}()
Diffstat (limited to 'Base/home/anon')
-rw-r--r--Base/home/anon/js/date.js29
1 files changed, 7 insertions, 22 deletions
diff --git a/Base/home/anon/js/date.js b/Base/home/anon/js/date.js
index 56a40d619c..160786e0bc 100644
--- a/Base/home/anon/js/date.js
+++ b/Base/home/anon/js/date.js
@@ -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);