Skip to content

Commit 0517c73

Browse files
authored
Merge pull request #312 from Ninjavin/digital-clock-js
Digital Clock in JS
2 parents 5a6d92d + 46bc9a2 commit 0517c73

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

JavaScript/Digital-Clock/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Digital Clock
2+
3+
This is a simple digital clock written using HTML, CSS and JS.
4+
5+
## How to Run?
6+
7+
Double Click on index.html and you will be good to go.
8+
9+
## Screenshot
10+
11+
![image](images/Digital-Clock.png)
Loading

JavaScript/Digital-Clock/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Digital Clock</title>
8+
</head>
9+
<body>
10+
<div id="digitalClock">
11+
12+
</div>
13+
<script src="index.js"></script>
14+
</body>
15+
</html>

JavaScript/Digital-Clock/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function clock(){
2+
// Getting Time
3+
let now = new Date()
4+
let hours = now.getHours()
5+
let min = now.getMinutes()
6+
let seconds = now.getSeconds()
7+
hours = (hours < 10) ? `0${hours}` : hours
8+
min = (min < 10) ? `0${min}` : min
9+
seconds = (seconds < 10) ? `0${seconds}` : seconds
10+
if(hours > 12){
11+
document.getElementById('digitalClock').innerHTML = `${hours%12}:${min}:${seconds} PM`
12+
}
13+
else
14+
document.getElementById('digitalClock').innerHTML = `${hours}:${min}:${seconds} AM`
15+
}
16+
setInterval(clock, 1000)

JavaScript/Digital-Clock/style.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body, html{
8+
height: 100%;
9+
width: 100%;
10+
margin: 0;
11+
padding: 0;
12+
background: #1661ee;
13+
font-family: Lato, arial;
14+
}
15+
16+
#digitalClock{
17+
position: absolute;
18+
top: 50%;
19+
left: 50%;
20+
transform: translate(-50%, -50%);
21+
-ms-transform: translate(-50%, -50%);
22+
-webkit-transform: translate(-50%, -50%);
23+
height: max-content;
24+
margin: auto;
25+
font-size: 7vw;
26+
color: white;
27+
}

0 commit comments

Comments
 (0)