diff options
author | Linus Groh <mail@linusgroh.de> | 2020-03-30 00:21:56 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-30 14:11:54 +0200 |
commit | d4e3688f4f5338ce5995a4c9bcce1e0bb961845f (patch) | |
tree | 63cc3d1676c4f232afa3aad4e6429393161ca910 /Base/home/anon/js | |
parent | 5c779c124b36fe314fa2a3a0a931ba033a47c5f1 (diff) | |
download | serenity-d4e3688f4f5338ce5995a4c9bcce1e0bb961845f.zip |
LibJS: Start implementing Date :^)
This adds:
- A global Date object (with `length` property and `now` function)
- The Date constructor (no arguments yet)
- The Date prototype (with `get*` functions)
Diffstat (limited to 'Base/home/anon/js')
-rw-r--r-- | Base/home/anon/js/date.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Base/home/anon/js/date.js b/Base/home/anon/js/date.js new file mode 100644 index 0000000000..56a40d619c --- /dev/null +++ b/Base/home/anon/js/date.js @@ -0,0 +1,29 @@ +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; +} +console.log("Date: " + year + "-" + month + "-" + day); +console.log("Time: " + hours + ":" + minutes + ":" + seconds + "." + milliseconds); |