2

I have measurements that were taken at this time: 13880 and they represent "days since 1970-01-01 00:00:00"

So now I want to know the dat and time:

as.Date(13880, origin="1970-01-01")
[1] "2008-01-02"  # works fine

Now to add the time:

as.Date(13880, origin="1970-01-01",tz = "UTC",  format="%Y/%m/%d %H:%M:%S")
[1] NA

or

as.POSIXct(13880, origin="1970-01-01")
[1] "1970-01-01 04:51:20 CET"
as.POSIXlt(13879, origin="1970-01-01")
[1] "1970-01-01 04:51:19 CET"

None of these worked for me. Any idea?

hyat
  • 1,047
  • 4
  • 15
  • 34

1 Answers1

2
as.POSIXct(as.Date("1970-01-01") + 13880) # returns "2008-01-01 19:00:00 EST"
as.POSIXct(as.Date("1970-01-01") + 13880.5) # returns "2008-01-02 07:00:00 EST"

You can also set your time zone: How to change the default time zone in R? also: http://blog.revolutionanalytics.com/2009/06/converting-time-zones.html

Community
  • 1
  • 1
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
  • 1
    I don't think this is correct. `as.Date` result depends on your systems default time zone (in your case is "EST"), while `13880` were measured in days, so where should you take the time from? – David Arenburg May 20 '15 at 12:22
  • 1
    @DavidArenburg the OP states that the starting time is 00:00 on 1970-01-01 (but does not specify TZ, so assuming UTC, which is the default input to `?as.Date`). My interpretation is that time should be taken from fractional days (the .5 of 13880.5 in the above example) and added to midnight --so adding half a day would get you to 12:00 UTC or 07:00 EST. – C8H10N4O2 May 20 '15 at 12:37
  • You maybe right, then you probably should specify `tz` within `as.Date` then – David Arenburg May 20 '15 at 12:41