0

I have a character that I would like to make class POISXct

This works as expected:

x = "2018-06-29 06:00:00"
as.POSIXct(x) ## "2018-06-29 06:00:00 EDT"

However if the hours should be 00:00:00 it is dropping everything but the date:

as.POSIXct(x) - hours(6) ##  "2018-06-29 EDT"

What do I have to change so that

as.POSIXct(x) - hours(6)

returns

"2018-06-29 00:00:00 EDT"
Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 1
    You misunderstand _internal representation_ (always at full precision) and _default display format_ (where it was decided to drop redundant information). But setting an _explicit_ format you can get what you have. This question has likely dozens of duplicates here. – Dirk Eddelbuettel Jun 29 '18 at 14:24
  • `format(x, '%Y-%m-%d %H:%M:%S')` thanks. – Rafael Jun 29 '18 at 14:26
  • Yup. I am not sure you can override the system default for `format.POSIXt` so besides a helper function you could sub-class. But that smells like overkill. – Dirk Eddelbuettel Jun 29 '18 at 14:31

0 Answers0