Spaces:
Build error
Build error
| 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") | |