0

I run the code below

library(dplyr)
library(lubridate)
xx1<-'20211222000010'
start_time <- strptime(xx1, format = "%Y%m%d%H%M%S")

wqdata_A <- tibble(time = as.POSIXct(10*((1:(1*8640))-1), origin = start_time))

20211222000010means December 22nd, 2021, 00:00:10 .

I expected that wqdata_A would give me the series of time starting from 2021-12-22 00:00:10because I set the origin as start_time. However, when I run the code, the starting time of wqdata_A is 2021-12-22 09:00:10. I don't know why the starting time changes even though I set the origin using tibble.

Lee
  • 369
  • 1
  • 6
  • 1
    I'm going to guess it's a timezone issue. Are you, by any chance, located in a timezone which is GMT + 9? POSIXct always uses GMT as the time zone. [This question](https://stackoverflow.com/questions/1395117/how-do-you-convert-dates-times-from-one-time-zone-to-another-in-r) may suggest some solutions. – Limey Jan 19 '22 at 09:10
  • I'm in South Korea. `start_time` gives `"2021-12-22 00:00:10 KST"` . – Lee Jan 19 '22 at 09:14
  • Exactly! KST is GMT + 9. You're providing `asPOSIXct()` with a datetime without a timezone. So it assumes GMT. But your tibble is printed using your locale, which is GMT + 9. R has NOT changed your starting time. Dealing with dates and times is not straightforward! My link above gives you your answer: provide a timezone when creating your sequewnce of datetimes. – Limey Jan 19 '22 at 09:17
  • Yeah! You're right. When I changed a timezone, it worked ! – Lee Jan 19 '22 at 09:40

0 Answers0