r - Convert to GMT time without changing date -


i query data base , vector of dates in est time

d =as.posixct(c("2015-06-19 00:38:08 est","2015-06-19 00:38:33 est")) d 

here vector

d [1] "2015-06-19 00:38:08 est" "2015-06-19 00:38:33 est" 

but want timezone in gmt time.

how can results

d [1] "2015-06-19 00:38:08 gmt" "2015-06-19 00:38:33 gmt" 

first, need have unambiguous way of making time in new york time (for est" ambiguous owing existence of eastern time zone in australia well. better est5edt or "america/new_york".) if run code used in different time zone don't same time:

> d =as.posixct(c("2015-06-19 00:38:08 est","2015-06-19 00:38:33 est")) > d [1] "2015-06-19 00:38:08 pdt" "2015-06-19 00:38:33 pdt" 

the time zone portion of character times ignored @ time of creation as.posixct. instead use:

> d =as.posixct(c("2015-06-19 00:38:08 est","2015-06-19 00:38:33 est"), tz="america/new_york", usetz=true) > d [1] "2015-06-19 00:38:08 edt" "2015-06-19 00:38:33 edt" 

notice correct display of daylight savings time has been displayed. can use format.posixt output of "the same time" in gmt/uct/utc timezone:

> format(d, tz="gmt") [1] "2015-06-19 04:38:08" "2015-06-19 04:38:33" 

i hope fair summary of how strptime handles datetime input:

date-times implicitly entered in current timezone set locale setting trailing tz indicator ignored no warning , stored uct offset determined locale's difference uct. timezone formatting %-'specials' used on output strftime , format.posixt.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -