0

I have a dataframe with timestamps, which look like this:

2020-06-28T16:45:04.3602059+03:00

I use anytime packages function anytime to transform its format:

df <- df %>%
    dplyr::mutate(
      timestamp = anytime::anytime(timestamp))

So after that timestamp looks like this:

2020-06-28 16:45:04

But i lost milliseconds here. How could i do that transformation with keeping milliseconds in case of this specific initial format?

french_fries
  • 1,149
  • 6
  • 22

1 Answers1

0

The milliseconds are preserved in the data, but the POSIXct class has a display method that truncates to the second. Using the second() function from the lubridate package, we can extract the seconds component of the POSIXct date.time and see that the milliseconds are still there:

library(anytime)
library(lubridate)
dt1 = anytime("2020-06-28T16:45:04.3602059+03:00")
second(dt1)
4.360205
Ben Norris
  • 5,639
  • 2
  • 6
  • 15