forked from larymak/Python-project-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7135dd
commit 22d46a7
Showing
3 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
### This is a simple program to print Custom current clock | ||
|
||
How use it : | ||
|
||
1- Choose your timezone in file timezones.txt | ||
|
||
2- python3 getting_current_time.py | ||
|
||
- output with Asia/Tehran timezone : | ||
Current time in this timezone: 2021:06:23 19:45:29 +0430 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from datetime import datetime | ||
import pytz | ||
from pytz import UnknownTimeZoneError | ||
|
||
# Get time zone name from user | ||
user_entered_time_zone = input('Enter your time zone: ') | ||
|
||
|
||
def get_current_time(time_zone_name): | ||
# It will get the time zone of the user location | ||
time_zone_name = pytz.timezone(time_zone_name) | ||
|
||
# Print the date and time in specified format | ||
current_time = datetime.now(time_zone_name) | ||
print(f"Current time in this timezone: {current_time.strftime('%Y:%m:%d %H:%M:%S %Z')}") | ||
|
||
|
||
try: | ||
get_current_time(user_entered_time_zone) | ||
except UnknownTimeZoneError: | ||
print('UnknownTimeZoneError... \nPlease try again with correct time zone.') |
Oops, something went wrong.