ID EN
Math Functions

round.POSIXt

R Base 3.6.2

Round or truncate date-time objects.

Syntax

R
# S3 method for POSIXt
round(x,
      units = c("secs", "mins", "hours", "days", "months", "years"))
# S3 method for POSIXt
trunc(x,
      units = c("secs", "mins", "hours", "days", "months", "years"),
      &#8230;)<p></p><p># S3 method for Date
round(x, &#8230;)
# S3 method for Date
trunc(x, &#8230;)</p>

Arguments

Parameter Description
x an object inheriting from "POSIXt" or "Date".
units one of the units listed. Can be abbreviated.
&#8230; arguments to be passed to or from other methods, notably digits for round.

Return Value

An object of class "POSIXlt" or "Date".

Details

The time is rounded or truncated to the second, minute, hour, day, month or year. Time zones are only relevant to days or more, when midnight in the current time zone is used. The methods for class "Date" are of little use except to remove fractional days.

Examples

Example
R
# NOT RUN {
round(.leap.seconds + 1000, "hour")
# }
# NOT RUN {
trunc(Sys.time(), "day")
# }

See Also

round for the generic function and default methods. DateTimeClasses Date