Search code examples
rtimetimestamptimestamp-with-timezone

Is there an R function that can convert datetime field which is in decimal form (41183.50417) to dd/mm/yyyy hh:mm:ss


I have an input file with datatime column which is filled with values of format (41183.50417), how do I interpret this and convert to Timestamp?

I tried using Lubridate but the output is with Time zone, code shown as below

as.POSIXct(as.Date(41183.50417, origin = '1900-01-01'),tz="")

The output is as shown below

2012-10-03 20:06:00 +08

How do I get rid of this '+08', Though I have given tz="", it keeps getting displayed

I have come across Unix Timestamp/epoch etc but this format (41183.50417) isn't clear to me.

I expect the output of 41183.50417 to be 21/02/1999 10:21:20


Solution

  • If you want to get rid of timezone display we can use format

    format(as.POSIXct(as.Date(41183.50417, origin = '1900-01-01')), "%Y-%m-%d %T")
    #[1] "2012-10-03 20:06:00"
    

    Read ?strptime for more format details.