How to format Datetime in JavaScript?

preview_player
Показать описание
Format Date and time in javascript and customize format.

Facebook Page

♥ Subscribe to our channel:

Links

Please give your feedback about video in Comment box.
Рекомендации по теме
Комментарии
Автор

<script>

// datetime object split into hour/minute/second
let hour = new Intl.DateTimeFormat('en',
{ hour: '2-digit', hourCycle: 'h24' }).format(d);

let minute = new Intl.DateTimeFormat('en',
{ minute: '2-digit' }).format(d);

let second = new Intl.DateTimeFormat('en',
{ second: '2-digit' }).format(d);

// 21:52:24

</script>

asimacademy
Автор

<script>

// datetime object split into hour/minute/second
let hour = new Intl.DateTimeFormat('en',
{ hour: '2-digit', hourCycle: 'h24' }).format(d);

let minute = new Intl.DateTimeFormat('en',
{ minute: '2-digit' }).format(d);

let second = new Intl.DateTimeFormat('en',
{ second: '2-digit' }).format(d);



</script>

asimacademy
Автор

<script>

//create datetime object and split into day/month/year
let d = new Date();
let year = new Intl.DateTimeFormat('en',
{ year: 'numeric' }).format(d); // 2-digit

let month = new Intl.DateTimeFormat('en',
{ month: 'long' }).format(d); // short|narrow

let day = new Intl.DateTimeFormat('en',
{ day: '2-digit' }).format(d);

// 22-October-2021

</script>

asimacademy
Автор

<script>

console.log(new Date().toJSON());
console.log(new Date().toDateString());
console.log(new Date().toISOString());
console.log(new Date().toLocaleDateString());
console.log(new Date().toLocaleString());
console.log(new Date().toLocaleTimeString());
console.log(new Date().toString());
console.log(new Date().toISOString());

</script>

asimacademy