4

I've build this dashboard with multiple date and time columns however in the dashboard the "T" and "Z" popup in the display LIKETHIS Any ideas on how to remove this? I tried as.character, as.factor, anytime but I'm not able to make it happen.

Any other ideas are appreciated!

kishore
  • 187
  • 4
  • 14
  • Suppose you converted the column to `character` i.e. `df1$time <- as.character(df1$time)` Can u show the output of the first five elements of that – akrun Aug 12 '17 at 15:30
  • @akrun, as.character was the first thing I tried but the "T" and "z" just don't go away! – kishore Aug 12 '17 at 16:35
  • @akrun, the output is the same as above there is no change! – kishore Aug 14 '17 at 04:08
  • @kishore have you tried the solution provided below? If it works, can you accept the answer? – Colin FAY Oct 10 '17 at 20:41

2 Answers2

5

This happens when you go from R to Javascript. You need to add:

 output$yourDT <- DT::renderDataTable({
     DT::datatable(df) %>% formatDate(3, "toLocaleString")
 })

Where the 3 represents the position of the date (as.POSIXct(), not factor, for example) column (e.g., third column) you are formatting.

calycolor
  • 726
  • 1
  • 7
  • 19
0

You can parse it in base R or with lubridate :

tz <- Sys.timezone()

date1 <- "2015-03-23T13:23:20Z"

# With {base}
strptime(date1, tz = tz, format = "%Y-%m-%dT%H:%M:%OSZ")
[1] "2015-03-23 13:23:20 CET"


#With lubridate
lubridate::ymd_hms(date1, tz = tz)
[1] "2015-03-23 14:23:20 CET"

You can of course specify a different timezone for tz.

Best,

Colin

Colin FAY
  • 4,849
  • 1
  • 12
  • 29