0

This should be the output: 20/2/06 11:16:16.123456789 But my output is "2006-02-20 11:16:16.123456 IST"

z <- strptime("20/2/06 11:16:16.123456789", "%d/%m/%y %H:%M:%OS")

z # prints without fractional seconds

op <- options(digits.secs = 9)

z
  • possible duplicate: https://stackoverflow.com/questions/7726034/how-r-formats-posixct-with-fractional-seconds – MrFlick May 21 '21 at 07:30
  • @MrFlick I have tried that and still didn't work. Only upto 6 digits even then. – renit Anthony May 21 '21 at 07:42
  • 1
    Don't think this is a duplicate of the other question. It has to do with the floating point precision, which is about 16-17 digits. See the output of `print(as.numeric(z),digits=22)`. In short: a double has not enough precision to represent more than 6 seconds digits. – nicola May 21 '21 at 07:46
  • @nicola It is not giving me the correct ouput even then. – renit Anthony May 21 '21 at 07:51
  • 1
    There is a discussion of precision there. And `z` happens to be POSIXlt in this case. `print(z$sec, digits=10)` does return more digits, but yeah, not exactly the same for floating point reasons. But yea, all the R formatting stuff is capped as 6 decimal digits according to `?strptime` – MrFlick May 21 '21 at 07:51
  • @MrFlick you are right, being a `POSIXlt` offers a little more room for the seconds. The answer is the doc you are reporting. – nicola May 21 '21 at 07:55
  • 1
    Try also `paste0(strftime(z,"%Y-%m-%d %H:%M"),":",z$sec)` to have a bunch of other digits. – nicola May 21 '21 at 07:59
  • @nicola thanks for this. This is exactly what i wanted . – renit Anthony May 21 '21 at 08:03

0 Answers0