Skip to content

Commit 018dcf7

Browse files
Digital Clock Using HTML, CSS and JavaScript
1 parent 6481e2b commit 018dcf7

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

Diff for: Digital_clock_using_JavaScript/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Digital Clock</title>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<h1 id="heading">Digital Clock</h1>
13+
<div class="clock-box">
14+
<div class="dateDay">
15+
<h3 id="date">hello</h3>
16+
<h3 id="day"></h3>
17+
</div>
18+
<p id="time">20:00:00</p>
19+
</div>
20+
<h3>Check Out my Potfolio for more amazing projects: <a href="https://harshilsharma.tech">HarshilSharma</a></h3>
21+
</div>
22+
<script src="script.js"></script>
23+
</body>
24+
</html>

Diff for: Digital_clock_using_JavaScript/script.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
window.onload = function(){
2+
startClock();
3+
}
4+
5+
let time = document.getElementById('time');
6+
7+
let currentData = new Date();
8+
9+
let date = currentData.getDate();
10+
let day = currentData.getDay();
11+
let month = currentData.getMonth();
12+
let year = currentData.getFullYear();
13+
14+
15+
let days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
16+
17+
day = days[day];
18+
19+
function startClock(){
20+
21+
let currentData = new Date();
22+
let seconds = currentData.getSeconds();
23+
let minutes = currentData.getMinutes();
24+
let hours = currentData.getHours();
25+
26+
27+
let AMorPM;
28+
if(hours>=12){
29+
AMorPM = "PM";
30+
}
31+
else{
32+
AMorPM = "AM";
33+
}
34+
35+
let h = hours;
36+
if(hours==0){
37+
h = 12;
38+
}
39+
else if(hours>12){
40+
h = hours-12;
41+
}
42+
43+
let s = check(seconds);
44+
let m = check(minutes);
45+
function check(val){
46+
if(val<10){
47+
return '0' + val;
48+
}
49+
return val;
50+
}
51+
52+
time.innerText = h + ':' + m + ':' + s + ' '+AMorPM;
53+
}
54+
55+
document.getElementById('date').innerText = date+'/ '+month+'/ '+year;
56+
document.getElementById('day').innerText = day;
57+
58+
59+
setInterval(startClock,1000);

Diff for: Digital_clock_using_JavaScript/style.css

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap');
2+
3+
*{
4+
padding: 0;
5+
margin: 0;
6+
}
7+
8+
body{
9+
background: #272c33;
10+
}
11+
12+
.container{
13+
max-width: 1200px;
14+
margin: 20px auto;
15+
padding: 30px;
16+
}
17+
18+
#heading{
19+
text-align: center;
20+
color: aqua;
21+
font-family: 'Ubuntu', sans-serif;
22+
font-size: 68px;
23+
}
24+
25+
.clock-box{
26+
height: 250px;
27+
width: 500px;
28+
margin: 110px auto;
29+
background: #3f4652;
30+
box-shadow: 0px 0px 20px 10px rgba(0, 0, 0, 0.315);
31+
color: aqua;
32+
display: flex;
33+
flex-direction: column;
34+
justify-content: center;
35+
}
36+
37+
.dateDay{
38+
display: flex;
39+
justify-content: space-between;
40+
margin: 1px 15px;
41+
}
42+
43+
#date{
44+
margin-top: 7px;
45+
font-family: 'Ubuntu', sans-serif;
46+
}
47+
48+
#day{
49+
margin-top: 7px;
50+
font-family: 'Ubuntu', sans-serif;
51+
}
52+
53+
#time{
54+
margin: auto;
55+
font-size: 62px;
56+
font-family: 'Ubuntu', sans-serif;
57+
}
58+
59+
h3{
60+
text-align: center;
61+
62+
color: rgba(0, 255, 255, 0.7);
63+
font-family: 'Ubuntu', sans-serif;
64+
}
65+
66+
h3 a{
67+
color: aqua;
68+
}

0 commit comments

Comments
 (0)