Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import datetime | |
| import pytz | |
| # List of available timezones | |
| TIMEZONES = pytz.all_timezones | |
| def convert_time(time_str, from_timezone, to_timezone): | |
| # Parse the input time string | |
| time_obj = datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S') | |
| # Set the from timezone | |
| from_tz = pytz.timezone(from_timezone) | |
| time_obj = from_tz.localize(time_obj) | |
| # Convert to the destination timezone | |
| to_tz = pytz.timezone(to_timezone) | |
| converted_time = time_obj.astimezone(to_tz) | |
| return converted_time.strftime('%Y-%m-%d %H:%M:%S') | |
| def main(): | |
| st.title('Time Zone Converter') | |
| # Input the time, from and to time zones | |
| time_input = st.text_input("Enter time (YYYY-MM-DD HH:MM:SS)", "2024-12-10 12:00:00") | |
| from_timezone = st.selectbox("From Time Zone", TIMEZONES) | |
| to_timezone = st.selectbox("To Time Zone", TIMEZONES) | |
| if st.button('Convert'): | |
| if time_input: | |
| try: | |
| converted_time = convert_time(time_input, from_timezone, to_timezone) | |
| st.write(f"Converted Time: {converted_time}") | |
| except Exception as e: | |
| st.error(f"Error: {str(e)}") | |
| else: | |
| st.error("Please enter a valid time.") | |
| if __name__ == "__main__": | |
| main() | |