Show a UTC Time in Another Zone

Hard ⏱ 18 min 30% acceptance ★★★★★ 4.8
Write in_zone(utc_dt, offset_hours) that takes a UTC-aware datetime and an integer offset (e.g. 5.5 for IST) and returns the wall-clock string 'HH:MM' in that zone, using timezone(timedelta(hours=offset_hours)) and astimezone — no pytz.

Examples

Example 1
Input
in_zone(datetime(2026, 1, 1, 12, 0, tzinfo=timezone.utc), 5.5)
Output
'17:30'
Explanation

Noon UTC is 17:30 IST.

Constraints

  • Standard library only.
  • Output format HH:MM zero-padded.

Topics

Date & Timetimezones

Companies

AtlassianGitLabZoom

Hints

Hint 1

timezone accepts a timedelta offset.

Hint 2

astimezone converts; strftime('%H:%M') formats.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.