Skip to content

Commit 788b6e1

Browse files
authored
Merge pull request larymak#32 from Saeedahmadi7714/current-time-script
Current time script
2 parents d7135dd + 85038e0 commit 788b6e1

File tree

4 files changed

+626
-1
lines changed

4 files changed

+626
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ When you Add a project Add it to the README for ease of finding it
7272

7373
* [Image Grayscalling](https://github.com/larymak/Python-project-Scripts/tree/main/Image%20Grayscalling)
7474

75-
* [Gettin Files and Folders sizes](https://github.com/Saeedahmadi7714/Python-project-Scripts/tree/main/Gettin%20File%20and%20Folder%20sizes)
75+
* [Getting Files and Folders sizes](https://github.com/Saeedahmadi7714/Python-project-Scripts/tree/main/Gettin%20File%20and%20Folder%20sizes)
7676

7777
_more coming soon_
7878

current_time/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### This is a simple program to print Custom current clock
2+
3+
How use it :
4+
5+
1- Choose your timezone in file timezones.txt
6+
7+
2- python3 getting_current_time.py
8+
9+
- output with Asia/Tehran timezone :
10+
Current time in this timezone: 2021:06:23 19:45:29 +0430
11+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from datetime import datetime
2+
import pytz
3+
from pytz import UnknownTimeZoneError
4+
5+
# Get time zone name from user
6+
user_entered_time_zone = input('Enter your time zone: ')
7+
8+
9+
def get_current_time(time_zone_name):
10+
# It will get the time zone of the user location
11+
time_zone_name = pytz.timezone(time_zone_name)
12+
13+
# Print the date and time in specified format
14+
current_time = datetime.now(time_zone_name)
15+
print(f"Current time in this timezone: {current_time.strftime('%Y:%m:%d %H:%M:%S %Z')}")
16+
17+
18+
try:
19+
get_current_time(user_entered_time_zone)
20+
except UnknownTimeZoneError:
21+
print('UnknownTimeZoneError... \nPlease try again with correct time zone.')

0 commit comments

Comments
 (0)