polars_xdt.format_localized#

polars_xdt.format_localized(expr: IntoExpr, format: str, locale: str = 'uk_UA') pl.Expr#

Convert to local datetime in given time zone.

Parameters:
expr

Expression to format.

format

Format string, see https://docs.rs/chrono/latest/chrono/format/strftime/index.html for what’s available.

locale

Locale to use for formatting. Defaults to “uk_UA”, because that’s what the OP requested pola-rs/polars#12341.

Returns:
Expr

Expression of data type Utf8.

Examples

>>> from datetime import datetime
>>> import polars_xdt as xdt
>>> df = pl.DataFrame(
...     {
...         "date_col": [datetime(2024, 8, 24), datetime(2024, 10, 1)],
...     }
... )
>>> df.with_columns(
...     result=xdt.format_localized(
...         "date_col", format="%A, %d %B %Y", locale="uk_UA"
...     )
... )
shape: (2, 2)
┌─────────────────────┬──────────────────────────┐
│ date_col            ┆ result                   │
│ ---                 ┆ ---                      │
│ datetime[μs]        ┆ str                      │
╞═════════════════════╪══════════════════════════╡
│ 2024-08-24 00:00:00 ┆ субота, 24 серпня 2024   │
│ 2024-10-01 00:00:00 ┆ вівторок, 01 жовтня 2024 │
└─────────────────────┴──────────────────────────┘