POSIXct2Character: Convert from POSIXct to Character

View source: R/POSIXct2Character.R

POSIXct2CharacterR Documentation

Convert from POSIXct to Character

Description

Convert objects from 'POSIXct' class to 'character' class.

Usage

POSIXct2Character(x, fmt = "%Y-%m-%d %H:%M:%OS3")

Arguments

x

'POSIXct' vector. Calendar date and time

fmt

'character' string. Conversion specification format

Value

A 'character' vector representing time.

Note

R incorrectly formats objects of calss 'POSIXct' with fractional seconds. For example, a 'POSIXct' time with fractional part .3 seconds (stored as 0.29999) is printed as .2 when represented with one decimal digit. The fractional part on outputs is not rounded. Decimal precision is down to milliseconds on Windows, and down to (almost) microseconds on the other operating systems.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

Examples

txt <- c("11/10/2011 07:49:36.3",
         "04/01/2013 17:22:08.123",
         "01/06/2013 01:02:16.123",
         "12/14/2038 15:42:04.123456")
date.time <- as.POSIXct(txt, format = "%m/%d/%Y %H:%M:%OS")

options("digits.secs" = 3)
format(date.time, fmt = "%d/%m/%Y %H:%M:%OS")
format(date.time, fmt = "%d/%m/%Y %H:%M:%OS3")

POSIXct2Character(date.time, fmt = "%d/%m/%Y %H:%M:%OS3")
POSIXct2Character(date.time, fmt = "%d/%m/%Y %H:%M:%OS4")
POSIXct2Character(date.time, fmt = "%d/%m/%Y %H:%M:%OS2")

POSIXct2Character(date.time, fmt = "%H:%M:%OS3 %Y-%m-%d")


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.