If you're observing that Local::now() in Rust using the Chrono crate is returning a time that's offset by one hour (e.g., in London during daylight saving time), then it's behaving as expected — because Local::now() returns the local time of the system where the code is executing, including any daylight saving time (DST) adjustments.
Let’s clarify with a few examples and how to ensure you're working with the correct timezone.
🔍 Common Confusion
❓Why is Local::now() off by 1 hour in London time?
This usually happens during British Summer Time (BST):
London follows:
GMT (UTC+0) during winter
BST (UTC+1) during summer
So if you're seeing UTC+1 in the summer, this is correct behavior.
✅ Checking Timezone Explicitly (with Chrono-tz)
By default, Chrono’s Local uses the system’s timezone. If you want to work specifically with London time, consider using the chrono-tz crate, which supports IANA time zones like "Europe/London" — and properly handles DST without depending on the system's local clock.
🔧 Add dependencies
toml
# In Cargo.toml
chrono = { version = "0.4", features = ["clock"] }
chrono-tz = "0.8"
✅ Example: Using Europe/London timezone explicitly
rust
use chrono::prelude::*;
use chrono_tz::Europe::London;
fn main() {
// Get the current time in UTC
let utc_now = Utc::now();
// Convert to London time
let london_time = utc_now.with_timezone(&London);
println!("UTC Time: {}", utc_now);
println!("London Time: {}", london_time);
}
This conversion will automatically handle daylight saving time correctly.
✅ Compare with Local::now()
If you run:
rust
use chrono::Local;
fn main() {
println!("Local time: {}", Local::now());
}
This will use your system's configured local time. If your system is configured to London time, and it's summertime, you'll see BST (UTC+1).
📌 Note: If you want to avoid relying on system timezones (especially for portability or consistency), prefer using chrono-tz with IANA zones like Europe/London.
✅ Summary
Function
Behavior
Local::now()
Uses system’s timezone (may include DST)
Utc::now()
Always in UTC, no offset
with_timezone(&London)
Converts UTC to correct London time including DST adjustments
Let me know if you want help detecting if DST is in effect or formatting the datetime!
User
anyway to do this automatically?
Assistant
Yes, you can automatically handle timezones and daylight saving time in Rust using Chrono + chrono-tz, without manually hardcoding timezone offsets or checking for DST yourself.
Here’s how to automatically get the current time in London, with the correct offset (handling DST under the hood):
✅ Automatic London Time with DST Handling
🚀 Solution Using chrono-tz
rust
use chrono::Utc;
use chrono_tz::Europe::London;
fn main() {
// Get current UTC time
let utc_now = Utc::now();
// Convert it to London time — automatically handles DST
let london_time = utc_now.with_timezone(&London);
println!("London time: {}", london_time);
}
👉 Output (during summer):
code
London time: 2025-06-15 14:12:00 BST
👉 Output (during winter):
code
London time: 2025-12-15 14:12:00 GMT
✔️ The output will automatically switch between GMT and BST depending on the current date.
✅ Dependency Setup
Add these to Cargo.toml:
toml
chrono = { version = "0.4", features = ["clock"] }
chrono-tz = "0.8"
❌ Why not use Local::now()?
Local::now() uses the system timezone, which might not be "Europe/London".
It can be off if the server or user's OS is set to a different time zone.
It doesn’t let you specify a zone explicitly like "Europe/London", so it’s not portable.
✅ Best Practice
If your goal is to consistently show time in a specific region (like the UK), always use: