Shahabmoin commited on
Commit
806b48b
·
verified ·
1 Parent(s): 196af6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datetime import datetime
3
+ import pytz
4
+
5
+ # List of available timezones
6
+ TIMEZONES = pytz.all_timezones
7
+
8
+ def convert_time(time_str, from_timezone, to_timezone):
9
+ # Parse the input time string
10
+ time_obj = datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S')
11
+
12
+ # Set the from timezone
13
+ from_tz = pytz.timezone(from_timezone)
14
+ time_obj = from_tz.localize(time_obj)
15
+
16
+ # Convert to the destination timezone
17
+ to_tz = pytz.timezone(to_timezone)
18
+ converted_time = time_obj.astimezone(to_tz)
19
+
20
+ return converted_time.strftime('%Y-%m-%d %H:%M:%S')
21
+
22
+ def main():
23
+ st.title('Time Zone Converter')
24
+
25
+ # Input the time, from and to time zones
26
+ time_input = st.text_input("Enter time (YYYY-MM-DD HH:MM:SS)", "2024-12-10 12:00:00")
27
+
28
+ from_timezone = st.selectbox("From Time Zone", TIMEZONES)
29
+ to_timezone = st.selectbox("To Time Zone", TIMEZONES)
30
+
31
+ if st.button('Convert'):
32
+ if time_input:
33
+ try:
34
+ converted_time = convert_time(time_input, from_timezone, to_timezone)
35
+ st.write(f"Converted Time: {converted_time}")
36
+ except Exception as e:
37
+ st.error(f"Error: {str(e)}")
38
+ else:
39
+ st.error("Please enter a valid time.")
40
+
41
+ if __name__ == "__main__":
42
+ main()