Skip to content

Commit f460f27

Browse files
current date javascript program
1 parent ee44133 commit f460f27

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

CurrentDate.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
3+
Write a JavaScript program to get the current date.
4+
5+
-->
6+
7+
<!DOCTYPE html>
8+
<html lang="en">
9+
<head>
10+
<meta charset="UTF-8">
11+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
13+
<title>Current Date</title>
14+
</head>
15+
16+
<body></body>
17+
18+
<script>
19+
20+
let today = new Date();
21+
let dd = today.getDate();
22+
23+
let mm = today.getMonth()+1;
24+
const yyyy = today.getFullYear();
25+
if(dd<10) {
26+
dd=`0${dd}`;
27+
}
28+
29+
if(mm<10) {
30+
mm=`0${mm}`;
31+
}
32+
33+
today = `${mm}-${dd}-${yyyy}`;
34+
console.log(today);
35+
36+
today = `${mm}/${dd}/${yyyy}`;
37+
console.log(today);
38+
39+
today = `${dd}-${mm}-${yyyy}`;
40+
console.log(today);
41+
42+
today = `${dd}/${mm}/${yyyy}`;
43+
console.log(today);
44+
45+
</script>
46+
47+
</html>

0 commit comments

Comments
 (0)