[R] Different time between date() and Sys.date()

David Winsemius dwinsemius at comcast.net
Thu Oct 21 19:53:22 CEST 2010


On Oct 21, 2010, at 11:59 AM, omerle wrote:

> Thanks for you answer.
> It s sufficient but I d like to know why my system think I am CEST  
> and yours think your are EDT.

It probably acquired it from your OS at the time of R's installation.  
(And that was not correct as I discovered.)

> Can I change it ?

Of course. (But not necessarily the way I would have predicted.)

?Sys.setlocale

 > Sys.getlocale()
[1] "en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8"

The arguments (and LC_TIME is but one of the arguments) are system  
dependent and you have not supplied that information. Furthermore, my  
efforts at changing my system (Mac 10.5.7/R2.11.1) were not successful.

 > Sys.setlocale(category = "LC_ALL" , locale= "de_DE")
[1] "de_DE/de_DE/de_DE/C/de_DE/en_US.UTF-8"
 > date()
[1] "Thu Oct 21 13:35:33 2010"
 > Sys.time()
[1] "2010-10-21 13:35:39 EDT"

?Sys.timezone

Made it clear that it is an OS setting and changing it in my system  
does the trick:

  > Sys.time()
[1] "2010-10-21 19:48:42 CEST"

-- 
David.

> Do you know where can I find a list of the timezone ?
>
> > Message du 21/10/10 15:07
> > De : "David Winsemius"
> > A : "omerle"
> > Copie à : r-help at r-project.org
> > Objet : Re: [R] Different time between date() and Sys.date()
> >
> >
> >
> > On Oct 21, 2010, at 6:19 AM, omerle wrote:
> >
> > > Hi,
> > >
> > > I got two different times between these functions :
> > >> date()
> > > [1] "Thu Oct 21 12:11:37 2010"
> > >> Sys.time()
> > > [1] "2010-10-21 10:11:40 GMT"
> > >>
> > >
> > > I know that its because I did Sys.setenv(TZ="GMT"). Even if my
> > > system is set by default at CEST.
> > > I think that the difference between date() and Sys.time() is equal
> > > to the difference between CEST and GMT.
> > > I would like to get the time of my machine even if I set GMT as a
> > > time zone with the Sys.time() function.
> > > How can I get the real time from the Sys.time() function ?
> > > Or I can really set my time zone to GMT to get the real time with
> > > Sys.time() ?
> >
> > > Sys.time()
> > [1] "2010-10-21 09:04:40 EDT"
> > > as.POSIXlt(Sys.time(), tz="GMT")
> > [1] "2010-10-21 13:06:40 GMT"
> >
> > >
> > > Thanks,
> > >
> > > Olivier Merle
> > >
> > > Une messagerie gratuite, garantie à vie et des services en plus,  
> ça
> > > vous tente ?
> > > Je crée ma boîte mail www.laposte.net
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help at r-project.org mailing list
> > > 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.
> >
> > David Winsemius, MD
> > West Hartford, CT
> >
> >
> >

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list