I would use the 'lubridate' package for this:

    > z <- Sys.time()
    > z
    [1] "2014-12-07 15:43:50 EST"
    > require(lubridate)
    > with_tz(z, "UTC")
    [1] "2014-12-07 20:43:50 UTC"




Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Sun, Dec 7, 2014 at 2:25 PM, Alemu Tadesse <alemu.tade...@gmail.com>
wrote:

> Dear R users
>
> I am puzzled by the following result from R script. I am trying to convert
> local time to UTC time. Time zone is -5, therefore I used the following
> approach.
>
> Below is the script.
> > Corrected_SA_data$date_time[k-1]
> [1] "2007-03-11 01:00:00"
> > Corrected_SA_data$TZ[k-1]
> [1] -5
> > Corrected_SA_data$date_time[k-1]-Corrected_SA_data$TZ[k-1]*3600
> [1] "2007-03-11 07:00:00 MDT"
>
> I was expecting this last value to be something like "2007-03-11 06:00:00
> UTC"
>
> Please correct me if I ma wrong.
>
> On the other hand I have
> > Corrected_SA_data$date_time[k]
> [1] "2007-03-11 02:00:00"
> > Corrected_SA_data$TZ[k]
> [1] -5
> > Corrected_SA_data$date_time[k]-Corrected_SA_data$TZ[k]*3600
> [1] NA
>
> I am not sure why I am getting NA.
>
> Thank you for your help.
>
> Alemu
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to