Skip to content

Commit

Permalink
Adding new current_time_script
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-avenkar committed Jun 23, 2021
1 parent d7135dd commit 22d46a7
Show file tree
Hide file tree
Showing 3 changed files with 625 additions and 0 deletions.
11 changes: 11 additions & 0 deletions current_time/README.md
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

21 changes: 21 additions & 0 deletions current_time/getting_current_time_zone.py
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.')
Loading

0 comments on commit 22d46a7

Please sign in to comment.