1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00
serenity/Base/home/anon/js/date.js
Linus Groh d4e3688f4f 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)
2020-03-30 14:11:54 +02:00

29 lines
836 B
JavaScript

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);