polars.Expr.dt.with_time_zone#

Expr.dt.with_time_zone(tz: str | None) Expr[source]#

Set time zone for a Series of type Datetime.

Parameters:
tz

Time zone for the Datetime Series.

Examples

>>> from datetime import datetime
>>> df = pl.DataFrame(
...     {
...         "date": pl.date_range(
...             datetime(2020, 3, 1), datetime(2020, 5, 1), "1mo"
...         ),
...     }
... )
>>> df.select(
...     [
...         pl.col("date"),
...         pl.col("date")
...         .dt.with_time_zone(tz="Europe/London")
...         .alias("London"),
...     ]
... )
shape: (3, 2)
┌─────────────────────┬─────────────────────────────┐
│ date                ┆ London                      │
│ ---                 ┆ ---                         │
│ datetime[μs]        ┆ datetime[μs, Europe/London] │
╞═════════════════════╪═════════════════════════════╡
│ 2020-03-01 00:00:00 ┆ 2020-03-01 00:00:00 GMT     │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2020-04-01 00:00:00 ┆ 2020-04-01 01:00:00 BST     │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2020-05-01 00:00:00 ┆ 2020-05-01 01:00:00 BST     │
└─────────────────────┴─────────────────────────────┘