File size: 1,606 Bytes
035089b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import pytz
from datetime import datetime

# Set the page config
st.set_page_config(page_title="World Time Converter", page_icon="⏳", layout="centered")

# Define available timezones
TIMEZONES = pytz.all_timezones

def convert_time(input_time, source_tz, target_tzs):
    source_tz = pytz.timezone(source_tz)
    localized_time = source_tz.localize(input_time)
    results = {}
    
    for tz in target_tzs:
        target_zone = pytz.timezone(tz)
        converted_time = localized_time.astimezone(target_zone)
        results[tz] = converted_time.strftime("%Y-%m-%d %H:%M %p")
    
    return results

# UI Design
st.title("🌍 World Time Converter")
st.markdown("Convert time between different time zones effortlessly!")

# User Inputs
col1, col2 = st.columns(2)

with col1:
    input_date = st.date_input("Select Date", datetime.today())
    input_time = st.time_input("Select Time", datetime.now().time())

with col2:
    source_timezone = st.selectbox("Select Source Timezone", TIMEZONES, index=TIMEZONES.index("UTC"))

destination_timezones = st.multiselect("Select Destination Timezones", TIMEZONES, default=["America/New_York", "Asia/Tokyo", "Europe/London"])

# Convert Time
if st.button("Convert Time"):
    input_datetime = datetime.combine(input_date, input_time)
    converted_times = convert_time(input_datetime, source_timezone, destination_timezones)
    
    st.subheader("Converted Times")
    for tz, time in converted_times.items():
        st.write(f"**{tz}**: {time}")

# Footer
st.markdown("---")
st.markdown("💡 Developed with ❤️ using Streamlit")