Skip to content

Commit 77c4b9c

Browse files
committed
New World Clock project added
1 parent fc4475e commit 77c4b9c

8 files changed

Lines changed: 279 additions & 0 deletions

File tree

Projects/World Clock/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# ⏲️ WORLD CLOCK 🌏
3+
4+
# What is it?
5+
As the name suggest this small program will help you get the realtime complete date and time of any timezone mentioned in the list.
6+
7+
## Tech Stack used
8+
- HTML
9+
- CSS
10+
- Javascript, Jquery
11+
- Basics of Bootstrap.
12+
13+
## Features
14+
- Get the Complete Time of any timezone.
15+
- Get the complete day, date, month and year of any timezone.
16+
17+
## Demo images of the project
18+
![Project demo 1](assets/img1.png)
19+
---
20+
![Project demo 2](assets/img2.png)
21+
---
22+
![Project demo 3](assets/img3.png)
23+
---
24+
![Project demo 3](assets/img4.png)
25+
---
26+
27+
## How to run it locally?
28+
- Fork the repository.
29+
- Clone the repository by using the command:-
30+
---
31+
git clone [github url of the repository]
32+
33+
- go to the directory of the project using command:-
34+
---
35+
cd [path of the project folder]
36+
37+
- Open the index.html file in any browser and see it running :)
38+
39+
### Thank you :)
40+
41+
42+
48.9 KB
Loading
50.1 KB
Loading
49.7 KB
Loading
39.6 KB
Loading

Projects/World Clock/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
<title>World Clock</title>
7+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<h1 class="title">⏲️ WORLD CLOCK 🌏</h1>
12+
<div class="datetime">
13+
<div class="dates">
14+
<span class="day">Day</span>,
15+
<span class="month">Month</span>
16+
<span class="date">Date</span>,
17+
<span class="year">Year</span>
18+
</div>
19+
<div class="time">
20+
<span class="hours">00</span>:
21+
<span class="minutes">00</span>:
22+
<span class="seconds">00</span>
23+
<span class="period">AM</span>
24+
</div>
25+
</div>
26+
<div class="timezone-toggle">
27+
<label for="timezone-select">Select Timezone:</label>
28+
<select id="timezone-select">
29+
</select>
30+
</div>
31+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
32+
<script src="./script.js"></script>
33+
</body>
34+
</html>

Projects/World Clock/script.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
//selecting all the elements to manipulate
3+
const dayElement = document.querySelector('.day');
4+
const monthElement = document.querySelector('.month');
5+
const dateElement = document.querySelector('.date');
6+
const yearElement = document.querySelector('.year');
7+
const hoursElement = document.querySelector('.hours');
8+
const minutesElement = document.querySelector('.minutes');
9+
const secondsElement = document.querySelector('.seconds');
10+
const periodElement = document.querySelector('.period');
11+
const timezoneSelectElement = document.querySelector('#timezone-select');
12+
13+
// List of timezones
14+
const timezones = [
15+
{ name: 'India', offset: '+0530' },
16+
{ name: 'New York', offset: '-0400' },
17+
{ name: 'London', offset: '+0100' },
18+
{ name: 'Tokyo', offset: '+0900' },
19+
{ name: 'Sydney', offset: '+1000' },
20+
{ name: 'Paris', offset: '+0200' },
21+
{ name: 'Berlin', offset: '+0200' },
22+
{ name: 'Moscow', offset: '+0300' },
23+
{ name: 'Los Angeles', offset: '-0700' },
24+
{ name: 'Chicago', offset: '-0500' },
25+
{ name: 'Denver', offset: '-0600' },
26+
{ name: 'Phoenix', offset: '-0700' },
27+
{ name: 'Toronto', offset: '-0400' },
28+
{ name: 'Vancouver', offset: '-0700' },
29+
{ name: 'Mexico City', offset: '-0500' },
30+
{ name: 'Sao Paulo', offset: '-0300' },
31+
{ name: 'Buenos Aires', offset: '-0300' },
32+
{ name: 'Dubai', offset: '+0400' },
33+
{ name: 'Beijing', offset: '+0800' },
34+
{ name: 'Jakarta', offset: '+0700' }
35+
// Add more timezones here
36+
];
37+
38+
// Function to update the world clock with current date and time
39+
function updateClock() {
40+
const now = new Date();
41+
42+
// Get current date
43+
const day = now.toLocaleString('en-US', { weekday: 'long' });
44+
const month = now.toLocaleString('en-US', { month: 'long' });
45+
const date = now.getDate();
46+
const year = now.getFullYear();
47+
48+
// Get current time
49+
let hours = now.getHours();
50+
const minutes = now.getMinutes();
51+
const seconds = now.getSeconds();
52+
const period = hours >= 12 ? 'PM' : 'AM';
53+
54+
// Adjust hours to 12-hour format
55+
hours = hours % 12 || 12;
56+
57+
// Update DOM elements with current values
58+
dayElement.textContent = day;
59+
monthElement.textContent = month;
60+
dateElement.textContent = date;
61+
yearElement.textContent = year;
62+
hoursElement.textContent = hours.toString().padStart(2, '0');
63+
minutesElement.textContent = minutes.toString().padStart(2, '0');
64+
secondsElement.textContent = seconds.toString().padStart(2, '0');
65+
periodElement.textContent = period;
66+
67+
// Schedule the next update
68+
setTimeout(updateClock, 1000);
69+
}
70+
71+
// Populate timezone select options
72+
for (const timezone of timezones) {
73+
const option = document.createElement('option');
74+
option.value = timezone.offset;
75+
option.textContent = timezone.name;
76+
timezoneSelectElement.appendChild(option);
77+
}
78+
79+
// Add event listener to handle timezone change
80+
timezoneSelectElement.addEventListener('change', (event) => {
81+
const offset = event.target.value;
82+
const currentTime = new Date().getTime();
83+
const targetTime = currentTime + (parseInt(offset) * 3600000); // Offset in milliseconds
84+
const targetDate = new Date(targetTime);
85+
const timezone = timezones.find(tz => tz.offset === offset);
86+
87+
// Update DOM elements with target values
88+
dayElement.textContent = targetDate.toLocaleString('en-US', { weekday: 'long' });
89+
monthElement.textContent = targetDate.toLocaleString('en-US', { month: 'long' });
90+
dateElement.textContent = targetDate.getDate();
91+
yearElement.textContent = targetDate.getFullYear();
92+
hoursElement.textContent = targetDate.getHours().toString().padStart(2, '0');
93+
minutesElement.textContent = targetDate.getMinutes().toString().padStart(2, '0');
94+
secondsElement.textContent = targetDate.getSeconds().toString().padStart(2, '0');
95+
periodElement.textContent = targetDate.getHours() >= 12 ? 'PM' : 'AM';
96+
97+
// Display selected timezone
98+
if (timezone) {
99+
console.log(`Selected timezone: ${timezone.name}`);
100+
}
101+
});
102+
103+
// Start the clock
104+
updateClock();

Projects/World Clock/style.css

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
*{
2+
padding: 0;
3+
margin: 0;
4+
}
5+
6+
body{
7+
height: 100vh;
8+
padding: 5%;
9+
/* display: flex; */
10+
justify-content: center;
11+
align-items: center;
12+
text-align: center;
13+
background: rgb(28, 1, 81);
14+
color: #fff;
15+
font-size: 1.4rem;
16+
/* flex-wrap: wrap; */
17+
}
18+
19+
.title{
20+
margin-top: 0;
21+
margin-bottom: 20vh;
22+
}
23+
24+
.datetime{
25+
text-align: center;
26+
justify-content: center;
27+
align-items: center;
28+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
29+
width: 340px;
30+
background: rgb(28, 1, 81);
31+
border: 5px solid white;
32+
padding: 30px 20px;
33+
margin: auto;
34+
border-radius: 10px;
35+
text-align: center;
36+
}
37+
38+
.date{
39+
font-size: 1.1rem;
40+
font-weight: 600;
41+
letter-spacing: 3px;
42+
}
43+
44+
.time{
45+
font-size: 3rem;
46+
display: flex;
47+
justify-content: center;
48+
align-items: center;
49+
}
50+
51+
.time span:not(:last-child){
52+
position: relative;
53+
margin: 0 6px;
54+
font-weight: 600;
55+
letter-spacing: 3px;
56+
}
57+
58+
.time span:last-child{
59+
background: rgb(230, 230, 230);
60+
color: blueviolet;
61+
padding: 0 3px;
62+
font-size: 25px;
63+
text-transform: uppercase;
64+
border-radius: 5px;
65+
margin-top: 10px;
66+
}
67+
68+
.timezone-toggle{
69+
margin-top: 10vh;
70+
font-size: 1.5rem;
71+
font-family:cursive;
72+
}
73+
74+
.timezone-toggle select{
75+
border-radius: 5px;
76+
border: 2px ;
77+
background: rgb(2, 76, 69);
78+
color: white;
79+
margin: 10px;
80+
text-align: center;
81+
overflow-y: auto;
82+
overflow-x: hidden;
83+
scrollbar-width: none; /* For Firefox */
84+
-ms-overflow-style: none;
85+
max-height: 50px;
86+
}
87+
88+
select::after{
89+
border: 2px solid white;
90+
}
91+
92+
#timezone-select::-webkit-scrollbar {
93+
display: none;
94+
}
95+
96+
/* Optional: Add some padding to the dropdown options */
97+
#timezone-select option {
98+
padding: 5px 10px;
99+
}

0 commit comments

Comments
 (0)