Learn R Programming

base (version 3.2.1)

round.POSIXt: Round / Truncate Data-Time Objects

Description

Round or truncate date-time objects.

Usage

"round"(x, units = c("secs", "mins", "hours", "days")) "trunc"(x, units = c("secs", "mins", "hours", "days"), ...)
"round"(x, ...) "trunc"(x, ...)

Arguments

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

Value

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

Details

The time is rounded or truncated to the second, minute, hour or day. Time zones are only relevant to days, when midnight in the current time zone is used.

The methods for class "Date" are of little use except to remove fractional days.

See Also

round for the generic function and default methods.

DateTimeClasses, Date

Examples

Run this code
round(.leap.seconds + 1000, "hour")
trunc(Sys.time(), "day")

Run the code above in your browser using DataLab