Join Me For a Live Information Session About Cohort Courses This Thursday • Plus Some `datetime.datetime` Magic
A brief announcement email • Hybrid cohort courses • Info session • End of 50% off • Work out the correct time using `datetime.datetime`
A rare announcement post from me–but I’m also putting in some relevant Python code–I couldn’t resist!
I'm running an information session this Thursday 29 February at 6:00pm GMT/UTC (more timezones below plus datetime.datetime
code to work it out yourself!) to introduce the new hybrid-live cohort courses. The first course, Beyond the Basics, will run between 15 April and 10 May.
You can join the live session either via Zoom or on an X / Twitter Space, whichever is more convenient. I'll discuss how the course runs, and why it's a "hybrid" course–part self-led and part live sessions, and with office hours and plenty of support. I'll also talk about the level of the course so you can determine whether it's what you need at this stage. And of course, I'll answer any questions you have.
Here are the links to register and join this free session:
You can also read more about the cohort courses on the website, of course. All cohort courses are available for free for members of The Python Coding Place.
Finally, a reminder that the 50% discount on lifetime membership of The Python Coding Place ends this Thursday, 29 February (end of day GMT/UTC)
Hope to see you on Thursday…
What time is the session where you are?
The live information session is this Thursday, 29 February at 6:00pm London time/GMT/UTC. But what about the time where you are?
Answer #1:
Here are some other timezones to make life easier for you…
6:00 PM London
1:00 PM New York
10:00 AM Los Angeles
7:00 PM Berlin
5:00 AM Sydney (+1d)
11:30 PM Kolkata
Answer #2:
Work it out yourself using `datetime.datetime`, of course! In fact, the output I showed you in the previous section showing several timezone was generated by Python code. Here it is:
Note: I wrote this code for personal use and not for a tutorial, so it can be neaters. Also, the format specifier %-I
, which gives the hour with a leading space if it’s one digit, is not standard and won’t work on Windows (I think–can’t check it as I don’t have a Windows machine). So replacy with the standard %I
if using Windows.
The code sets the local date and time in a list to enable converting several dates at once. The dates you see commented out are the dates for the cohort course live sessions and I used this code to create the session dates I show on the website.
I then loop through all these local dates, convert them to timezone aware `datetime.datetime` objects and loop through the output timezones I want.
I’m not giving this code the full “step-by-step tutorial treatment” I usually do in my standard articles, but you’re welcome to ask questions about it in the comments below…
Here’s the code in a copy-paste format:
import datetime
import zoneinfo
show_times_only = True
local_timezone = "Europe/London"
local_tz = zoneinfo.ZoneInfo(local_timezone)
# Set reference dates:
london_dates = [
"2024-02-29 6:00pm",
# "2024-04-18 6:00pm",
# "2024-04-25 6:00pm",
# "2024-05-02 6:00pm",
# "2024-05-09 6:00pm",
]
required_timezones = [
"Europe/London",
"America/New_York",
"America/Los_Angeles",
"Europe/Berlin",
"Australia/Sydney",
"Asia/Kolkata",
]
# Convert to timezones
for date in london_dates:
london_time = datetime.datetime.strptime(date, "%Y-%m-%d %I:%M%p")
london_time = london_time.replace(tzinfo=zoneinfo.ZoneInfo("Europe/London"))
for tz in required_timezones:
tz = zoneinfo.ZoneInfo(tz)
tz_time = london_time.astimezone(tz)
day_difference = (
f" ({(tz_time.date() - london_time.date()).days:+}d)"
if tz_time.day != london_time.day
else ""
)
if show_times_only:
print(
f"{tz_time:%l:%M %p} {tz.key.split('/')[1].replace('_', ' ')}{day_difference}"
)
else:
print(
f"{tz.key.split('/')[1].replace('_', ' '):12} {tz_time:%d %B %Y %-I:%M %p}"
)
if show_times_only:
print(f"{london_time.astimezone(zoneinfo.ZoneInfo('UTC')):%-I:%M %p} UTC/GMT\n")
else:
print(
f"UTC/GMT {london_time.astimezone(zoneinfo.ZoneInfo('UTC')):%d %B %Y %-I:%M %p}\n"
)
See You on Thursday?
Here are the links again to register and join this free session:
The one hour difference shouldn’t be linked to the f-string though. It could be earlier in your code?
Hi Rolf, this is a great note. I wrote this code for my personal use and it works but I use a non-standard format specifier which I believe doesn’t work on Windows. I assume you’re on Windows?
My version gives the hour without a leading zero but with a space. Normally I’d avoid these variations in my tutorials, but this wasn’t intended as a tutorial so I forgot!