[R] convert character to POSIXct

Aarts, Geert Geert.Aarts at wur.nl
Tue Sep 2 17:06:49 CEST 2003

Dear list-members,
I would like to calculate the difference between two points in time. To convert a 'time (GMT)'-character with the format "1/1/1999 01:01:01" into an object of class "POSIXct"', I first use the strptime() as suggested in the details help(as.POSIXct).
starttime<-strptime("1/1/1999 01:01:01",format="%d/%m/%Y %H:%M:%S")
endtime<-strptime("1/8/1999 01:01:01",format="%d/%m/%Y %H:%M:%S")
> starttime
[1] "1999-01-01 01:01:01"
> endtime
[1] "1999-08-01 01:01:01"

If I substract these from each other, 
>Time difference of 211.9583 days
Which should mean that the default is in day light saving.
Next I convert these times into as.POSIXct and substract them
[1] "1999-01-01 01:01:01 GMT Standard Time"
[1] "1999-08-01 01:01:01 GMT Standard Time"
Time difference of 211.9583 days

So although the calculation suggest time is in daylight saving, it actually states that it is in "GMT Standard Time"
Can somebody tell me whether my thoughts are correct and if not, tell me why this is happening?
> as.POSIXct(endtime, tz="GMT")-as.POSIXct(starttime, tz="GMT")
Time difference of 212 days
So this seems to work correctly.
Kinds regards, Geert (Windows, R-version 1.7.0)

More information about the R-help mailing list