0

I have a simple code converting my epoch time which is integer to "POSIXct" "POSIXt". The problem is that my actual experiment starting time and the converted time doesn't match ( off by 12 hours). I am not sure where is the problem from at this stage because I have an old sensor but here is my code. epoch is in the form of " 1533043920" in a column in my csv file.which is named Time..Unix.epoch.1970.The code works but I am not sure why I am off... any thoughts?

##### here is my epoch snapshot
> epoch
  [1] 1533043920 1533043980 1533044040 1533044100 1533044160 1533044220 1533044280 1533044340 1533044400 ...
#### Here is my code for conversion
epoch<-filedf$Time..Unix.epoch.1970.
# checking class
class(epoch)
# convert to POSIXct format
R <- as.POSIXct(epoch, origin="1970-01-01")
R
class(R)
## Answer
> class(epoch)
[1] "integer"
> class(R)
[1] "POSIXct" "POSIXt" 

## Answer 
[1] "2018-07-31 21:32:00 AWST" "2018-07-31 21:33:00 AWST" "2018-07-31 21:34:00 AWST"
  [4] "2018-07-31 21:35:00 AWST" "2018-07-31 21:36:00 AWST" "2018-07-31 21:37:00 AWST"...
rains
  • 23
  • 6
  • You can try specifying the timezone (`tz=`) in the as.POSIXct function. The epoch might be in UTC time and not AWST. This might help: https://stackoverflow.com/questions/14141537/change-timezone-in-a-posixct-object – Dave2e Aug 14 '18 at 13:09
  • I did.. it doesn't recognize AWST time zone. Also, the code doesn't change it to my local time if I add the tz= "UTC" it is adding an additional step I don't think I need. It only worked when I did this ## R <- as.POSIXct(epoch , origin="1970-01-01 14:00:00") – rains Aug 15 '18 at 11:25
  • the starting time becomes reasonable, however, the end time is off by 2 hours now. I am not sure what is happening its either lose 14 hours or gain extra two hours! – rains Aug 15 '18 at 11:31
  • Your question is unclear of what your expected values should be, thus it is difficult to provide more assistance. Use `OlsonNames()` function to see a list of acceptable time zones. Your epoch variable is a time stamp, but what is the expected local time (ie including timezone) are you expecting? – Dave2e Aug 15 '18 at 13:55
  • The expected time zone is "Australia/Perth" I have tried it but I am still off. I will do another run and see if its a sensor issue. – rains Aug 16 '18 at 01:53

0 Answers0