Update app.py
Browse files
app.py
CHANGED
|
@@ -28,8 +28,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 28 |
# Create timezone object
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
# Get current time in that timezone
|
| 31 |
-
local_time = datetime.datetime.now(tz).strftime("%
|
| 32 |
-
return f"The current local time in {timezone} is: {local_time}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
| 28 |
# Create timezone object
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
# Get current time in that timezone
|
| 31 |
+
#local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 32 |
+
#return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
+
#################################
|
| 34 |
+
now = datetime.datetime.now(tz)
|
| 35 |
+
|
| 36 |
+
hour_min = now.strftime("%-I:%M %p") # 6:05 PM
|
| 37 |
+
month_year = now.strftime("%b %Y") # Jan 2026
|
| 38 |
+
day = now.day
|
| 39 |
+
|
| 40 |
+
# Ordinal suffix logic
|
| 41 |
+
suffix = "th" if 11 <= day <= 13 else {1: "st", 2: "nd", 3: "rd"}.get(day % 10, "th")
|
| 42 |
+
|
| 43 |
+
formatted_time = f"{hour_min} {now.strftime('%b')} {day}{suffix} {now.year}"
|
| 44 |
+
|
| 45 |
+
return f"The current local time in {timezone} is: {formatted_time}"
|
| 46 |
+
########################
|
| 47 |
except Exception as e:
|
| 48 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 49 |
|