Re: managing dates in POSIXct format at 00

Duncan Murdoch <[email protected]>
Newsgroups gmane.comp.lang.r.general
Message-ID <[email protected]>
On 2025-11-14 12:47 p.m., Iris Simmons wrote:
> R does this for convenience when printing values. But it's not always
> convenient when writing to a file. Instead, you could use strftime to
> convert to your desired character format before writing:
> 
> mydf$data_POSIX <- strftime(mydf$data_POSIX, "%Y-%m-%d %H:%M:%OS3")
> 
> you can optionally change the 3 to a number between 0 and 6. If you choose
> 0, it's easier to just use %S instead.

That can happen automatically if you set an as.character() method:

   as.character.POSIXct <- function(x, ...) strftime(x, "%Y-%m-%d 
%H:%M:%OS3")

(By default, there's a POSIXt method, but no POSIXct method.)

Time zone issues still make mydf2 different from mydf, but you won't get 
NAs.

Duncan Murdoch
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.