@@ -39,9 +39,11 @@ strptime(x, format, tz = "")
3939 methods is
4040 \code {" \% Y-\% m-\% d \% H:\% M:\% S" } if any element has a time
4141 component which is not midnight , and \code {" \% Y-\% m-\% d" }
42- otherwise. If \code {digits } is not \code {NULL }, i.e. , by default when
43- \code {\link {options }(" digits.secs" )} is set , up to
44- the specified number of digits will be printed for seconds. }
42+ otherwise. In the first case and if \code {digits } is not \code {NULL },
43+ i.e. , by default when \code {\link {options }(" digits.secs" )} is set , up to
44+ the specified number of digits will be printed for seconds , using
45+ \code {" \% OS<n>" } instead of \code {" \% S" } in the format , see also
46+ \sQuote {Details }. }
4547 \item {\dots }{further arguments to be passed from or to other methods. }
4648 \item {usetz }{logical. Should the time zone abbreviation be appended
4749 to the output ? This is used in printing times , and more reliable
@@ -237,7 +239,9 @@ strptime(x, format, tz = "")
237239 Specific to \R is \c ode{\% OSn}, which for output gives the seconds
238240 truncated to \c ode{0 <= n <= 6} decimal places (and if \c ode{\% OS} is
239241 not followed by a digit, it uses \c ode{digits} unless that is
240- \c ode{NULL}, when \c ode{n = 0}). Further, for \c ode{strptime}
242+ \c ode{NULL}, when \c ode{n = 0}). Note that the precedence is
243+ \c ode{format="...\% OSn"} \e qn{\l l}{>>} \c ode{digits = n} \e qn{\l l}{>>}
244+ \c ode{getOption("digits.prec")}. Further, for \c ode{strptime}
241245 \c ode{\% OS} will input seconds including fractional seconds. Note that
242246 \c ode{\% S} does not read fractional parts on output.
243247
@@ -424,14 +428,17 @@ z2 <- strptime(x, "\%m/\%d/\%y \%H:\%M:\%S")
424428## *here* (but not in general), the same as format():
425429stopifnot(identical(format(z2), as.character(z2)))
426430
427- ## time with fractional seconds
428- z3 <- strptime("20/2/06 11:16:16.683", "\% d/\% m/\% y \% H:\% M:\% OS") \d onttest{
431+ ## time with fractional seconds (setting `tz = ..` for reproducible output)
432+ z3 <- strptime("20/2/06 11:16:16.683", "\% d/\% m/\% y \% H:\% M:\% OS", tz = "UTC")
429433z3 # prints without fractional seconds by default, digits.sec = NULL ("= 0")
430- print(z3, digits = 3) # shows extra digits}
431- op <- options(digits.secs = 3)
432- \d onttest{z3 # shows the 3 extra digits}
433- as.character(z3) # ditto
434+ format(z3, digits = 3) # shows extra digits
435+ format(z3, digits = 6) # still 3 digits: *not* showing trailing zeros
436+ format(z3, format = "\% Y-\% m-\% d \% H:\% M:\% OS6") # *does* keep trailing zeros
437+ op <- options(digits.secs = 3) # global option, the default for `digits`
438+ z3 # shows the 3 extra digits
434439options(op)
440+ as.character(z3) # ditto
441+
435442
436443## time zone names are not portable, but ' EST5EDT ' comes pretty close.
437444## (but its interpretation may not be universal: see ?timezones)
0 commit comments