Skip to main content
`Ctrl`+`K`

# pandas.Timestamp.as_unit

Timestamp.as_unit(unit, round_ok=True)

  Convert the underlying int64 representation to the given unit.

  This method changes the resolution of the Timestamp’s internal representation. When converting to a coarser resolution (e.g., nanoseconds to seconds), precision may be lost through rounding unless `round_ok` is set to False.

  Parameters:
    unit{“ns”, “us”, “ms”, “s”}
    round_ok bool, default True

      If False and the conversion requires rounding, raise.

  Returns:
    Timestamp

  See also

  `Timestamp.asm8`

    Return numpy datetime64 format with same precision.

  `Timestamp.to_pydatetime`

    Convert Timestamp object to a native Python datetime object.

  `to_timedelta`

    Convert argument into timedelta object, which can represent differences in times.

  Examples

      >>> ts = pd.Timestamp('2023-01-01 00:00:00.01')
      >>> ts
      Timestamp('2023-01-01 00:00:00.010000')
      >>> ts.unit
      'us'
      >>> ts = ts.as_unit('s')
      >>> ts
      Timestamp('2023-01-01 00:00:00')
      >>> ts.unit
      's'