Dates with dttm format appear with a strange format when displayed in a DT:: datatable

Viewed 63

I have dataframe loaded by a csv which is like:

A tibble: 5 x 8
     ID EventType   EventDate           EventValue          EventValueExt1 EventValueExt2 EventValueExt3 EventValueExt4
  <dbl> <chr>       <dttm>              <chr>                        <dbl>          <dbl>          <dbl>          <dbl>
1 12340 steps       2019-11-26 21:18:00 3017                          NA               NA           NA               NA
2 12339 steps       2019-11-25 14:23:00 3016                          NA               NA           NA               NA
3 12338 steps       2019-11-25 14:00:00 3015                          NA               NA           NA               NA
4 12337 geo_logging 2019-11-22 19:10:00 40.748498,-73.9933~           16.4              0           16.8              0
5 12336 geo_logging 2019-11-22 19:09:00 40.7484843,-73.993~           22.2              0           16.8              0

Then I try to create a DT::datatable with: datatable(device1_report1583417393205)

and I get: enter image description here

As you can see my datetime has a strange format. I try

class(device1_report1583417393205$EventDate)
[1] "POSIXct" "POSIXt"

and then I try:

library(lubridate)
library(chron)
device1_report1583417393205$EventDate <- ymd_hms(device1_report1583417393205$EventDate)
chron(dates = format(device1_report1583417393205$EventDate, '%Y-%m-%d'), time = format(device1_report1583417393205$EventDate, "%H:%M:%S"), 
      format = c('y-m-d', 'h:m:s'))

but still get the same result in my DT. I also tried to make them factors but still the same. Any ideas?

EDIT:REPRODUCIBLE EXAMPLE

require(lubridate)
require(dplyr)

df = data.frame(timestring = c("2015-12-12 13:34:56", "2015-12-14 16:23:32"),
                localzone = c("America/Los_Angeles", "America/New_York"), stringsAsFactors = F)

df$moment = as.POSIXct(df$timestring, format="%Y-%m-%d %H:%M:%S", tz="UTC")

df = df %>% rowwise() %>% mutate(localtime = force_tz(moment, localzone))

df
DT::datatable(df)
0 Answers
Related