-
Notifications
You must be signed in to change notification settings - Fork 0
/
53. Format_the_date.js
36 lines (32 loc) · 1.03 KB
/
53. Format_the_date.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//*---------- format the date
//? Formatting a date in javascript typically involves using the toLocaleDateString() method or constructing a formatted string manually . The toLocaleDateString() method provides a way to format a date based on the user's locale including options for formatting the date, such as specifying the date style and time zone.
function formatDate() {
let date = new Date();
let formattedDate = date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
weekday: "long",
timeZone: "Asia/kolkata",
});
console.log(formattedDate);
return formattedDate;
}
formatDate();
//*----- to format the time also along with date
function formatDate() {
let date = new Date();
let formattedDate = date.toLocaleString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
weekday: "long",
timeZone: "Asia/kolkata",
});
console.log(formattedDate);
return formattedDate;
}
formatDate();