polars convert-time-zone

For dataframe.

Convert datetime to target timezone.

warning This command requires a plugin The polars convert-time-zone command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.

Command Type

plugin

Signature

> polars convert-time-zone {flags} (time_zone)

Parameters

  • time_zone: Timezone for the Datetime Series. Pass null to unset time zone.

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Convert timezone for timezone-aware datetime

> ["2025-04-10 09:30:00 -0400" "2025-04-10 10:30:00 -0400"] | polars into-df
                    | polars as-datetime "%Y-%m-%d %H:%M:%S %z"
                    | polars select (polars col datetime | polars convert-time-zone "Europe/Lisbon")
╭───┬────────────╮
│ # │  datetime  │
├───┼────────────┤
│ 0 │ a year ago │
│ 1 │ a year ago │
╰───┴────────────╯

Timezone conversions for timezone-naive datetime will assume the original timezone is UTC

> ["2025-04-10 09:30:00" "2025-04-10 10:30:00"] | polars into-df
                    | polars as-datetime "%Y-%m-%d %H:%M:%S" --naive
                    | polars select (polars col datetime | polars convert-time-zone "America/New_York")
╭───┬────────────╮
│ # │  datetime  │
├───┼────────────┤
│ 0 │ a year ago │
│ 1 │ a year ago │
╰───┴────────────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.