t.ct = as.POSIXct("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
t.lt = as.POSIXlt("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
t.st = strptime("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z")
Questi sembrano essere gli stessi tempi:determinare e impostare fuso orario in POSIXct, POSIXlt, strptime, ecc in R
> t.ct -t.lt
Time difference of 0 secs
> t.ct -t.st
Time difference of 0 secs
> str(t.ct)
POSIXct[1:1], format: "2009-01-04 21:19:00"
> str(t.lt)
POSIXlt[1:1], format: "2009-01-04 21:19:00"
> str(t.st)
POSIXlt[1:1], format: "2009-01-04 21:19:00"
>
Ma questi sembrano avere le informazioni fuso orario differente in loro, ed è non ciò che mi aspettavo:
> strftime(t.ct,"%Y-%m-%d %H:%M:%S %z")
[1] "2009-01-04 21:19:00 -0500"
> strftime(t.lt,"%Y-%m-%d %H:%M:%S %z")
[1] "2009-01-04 21:19:00 +1200"
> strftime(t.st,"%Y-%m-%d %H:%M:%S %z")
[1] "2009-01-04 21:19:00 +1200"
>
Il fuso orario sul mio Mac è:
> Sys.timezone()
[1] "America/New_York"
Le domande Difference between as.POSIXct/as.POSIXlt and strptime for converting character vectors to POSIXct/POSIXlt e as.POSIXlt ignores tz argument sembravano correlate, ma non lo chiarivano per me.
Come impostare un orario e usarlo definitivamente?
Aggiornamento:
Dalla risposta di user3293236 sotto, sembra uno dovrebbe sempre dichiarare il fuso orario della stringa, e se si sta analizzando la '-hhmm' offset, quindi utilizzare sempre tz="UTC"
:
t.ct = as.POSIXct("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z", tz="UTC")
t.lt = as.POSIXlt("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z", tz="UTC")
t.st = strptime("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z", tz="UTC")
Oh questo è un difetto terribile. L'esempio '' strptime' 'strptime (" Tue, 23 mar 2010 14:36:38 -0400 ","% a,% d% b% Y% H:% M:% S% z ") ' deve essere impostato 'tz = 'UTC', e nota che significa locale sugli altri esempi. Grazie per la nota attr (x, 'tzone'). Suppongo che per POSIXct, l'attributo tzone sia il fuso orario di segnalazione predefinito per l'oggetto, ma per POSIXlt sembra regolare l'origine. –