Built-in Class

Run Settings
LanguageJavaScript
Language Version
Run Command
// #1 tanpa parameter, yang berarti `myDate` akan berisi tanggal dan waktu saat ini const myDate = new Date(); console.log(myDate.getMonth()); // #2 parameter tanggal dalam bentuk string, misal "January 01, 2021" const myDate1 = new Date("January 01, 2021" ); console.log(myDate1.getFullYear()); // #3 parameter dalam bentuk number, misal 87400000 const myDate2 = new Date(97400000); console.log(myDate2.getHours()) // #4 parameter tanggal dalam bentuk number (7 parameter), [hour,minute,second,millisecond] bersifat opsional const myDate3 = new Date(); console.log(Date.parse("2021-01-01")); const ubahTanggal = new Date("01-12-2022"); console.log(ubahTanggal.getDate()); console.log(ubahTanggal.getMonth()); // parameter birthday dapat berupa miliseconds ataupun date string const myAge = birthday => { const birtday = new Date(birthday); const today = Date.now(); // today menghasilkan nilai miliseconds saat ini const diff_ms = today - birtday.getTime(); // menghitung selisih nilai miliseconds hari ini dan tanggal lahir const diffDate = new Date(diff_ms); return diffDate.getFullYear() - 1970; // 1970 adalah representasi 0 dari miliseconds }; console.log(myAge('1993-10-08')); // 21 tahun
Editor Settings
Theme
Key bindings
Full width
Lines