maaz21 commited on
Commit
035089b
·
verified ·
1 Parent(s): c509ba5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pytz
3
+ from datetime import datetime
4
+
5
+ # Set the page config
6
+ st.set_page_config(page_title="World Time Converter", page_icon="⏳", layout="centered")
7
+
8
+ # Define available timezones
9
+ TIMEZONES = pytz.all_timezones
10
+
11
+ def convert_time(input_time, source_tz, target_tzs):
12
+ source_tz = pytz.timezone(source_tz)
13
+ localized_time = source_tz.localize(input_time)
14
+ results = {}
15
+
16
+ for tz in target_tzs:
17
+ target_zone = pytz.timezone(tz)
18
+ converted_time = localized_time.astimezone(target_zone)
19
+ results[tz] = converted_time.strftime("%Y-%m-%d %H:%M %p")
20
+
21
+ return results
22
+
23
+ # UI Design
24
+ st.title("🌍 World Time Converter")
25
+ st.markdown("Convert time between different time zones effortlessly!")
26
+
27
+ # User Inputs
28
+ col1, col2 = st.columns(2)
29
+
30
+ with col1:
31
+ input_date = st.date_input("Select Date", datetime.today())
32
+ input_time = st.time_input("Select Time", datetime.now().time())
33
+
34
+ with col2:
35
+ source_timezone = st.selectbox("Select Source Timezone", TIMEZONES, index=TIMEZONES.index("UTC"))
36
+
37
+ destination_timezones = st.multiselect("Select Destination Timezones", TIMEZONES, default=["America/New_York", "Asia/Tokyo", "Europe/London"])
38
+
39
+ # Convert Time
40
+ if st.button("Convert Time"):
41
+ input_datetime = datetime.combine(input_date, input_time)
42
+ converted_times = convert_time(input_datetime, source_timezone, destination_timezones)
43
+
44
+ st.subheader("Converted Times")
45
+ for tz, time in converted_times.items():
46
+ st.write(f"**{tz}**: {time}")
47
+
48
+ # Footer
49
+ st.markdown("---")
50
+ st.markdown("💡 Developed with ❤️ using Streamlit")