Re: [R] formating chron date times for printing

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 29 Jun 2010 14:57:48 -0400

The time zone independent solution, i.e. paste(as.Date(x), format(x - floor(x))),
is the safer although format(as.POSIXlt(x, tz = "GMT")) seems to work too.

On Tue, Jun 29, 2010 at 2:44 PM, stephen sefick <ssefick_at_gmail.com> wrote:
> Thank you both!  If I don't want to deal with a Time Zone potentailly
> converting some of the dates, which would be your suggestions.  Or,
> are they all the same way to skin a cat.  Again thank you for your
> wonderful help.
> kindest regards,
>
> Stephen Sefick
>
>
> On Tue, Jun 29, 2010 at 1:39 PM, Gabor Grothendieck
> <ggrothendieck_at_gmail.com> wrote:
>> On Tue, Jun 29, 2010 at 2:22 PM, Gabor Grothendieck
>> <ggrothendieck_at_gmail.com> wrote:
>>> On Tue, Jun 29, 2010 at 2:01 PM, stephen sefick <ssefick_at_gmail.com> wrote:
>>>> the date were created with chron with this argument
>>>>
>>>> format=c(dates="Y/m/d", times="H:M:S"))
>>>>
>>>> so I have the dates being displayed as
>>>>
>>>> (10/06/22 12:00:00)
>>>>
>>>> I would like to have them displayed as
>>>>
>>>> "2010-06-22 12:00:00" or "%Y-%m-%d %H:%M:%S"
>>>>
>>>> and then I can convert these for mergeing with another data frame
>>>>
>>>> x <- (structure(c(14464, 14464.0104166667, 14464.0208333333, 14464.03125,
>>>> 14464.0416666667), format = structure(c("Y/m/d", "H:M:S"), .Names = c("dates",
>>>> "times")), origin = c(1, 1, 1970), class = c("chron", "dates",
>>>> "times")))
>>>>
>>>> reading through old posts I found this:
>>>>
>>>> format(x, enclosed = c("", ""))
>>>>
>>>> which put the which surrounds the date time with "" instead of ()
>>>> now I would like to change the format of the dates to print like the
>>>> above specified.
>>>> kindest regards,
>>>>
>>>
>>> Try this:
>>>
>>>> format(as.POSIXlt(x, tz = "GMT"))
>>> [1] "2009-08-08 00:00:00" "2009-08-08 00:15:00" "2009-08-08 00:29:59"
>>> [4] "2009-08-08 00:45:00" "2009-08-08 01:00:00"
>>>
>>
>> Also here is another solution:
>>
>>> paste(as.Date(x), format(x - floor(x)))
>> [1] "2009-08-08 00:00:00" "2009-08-08 00:15:00" "2009-08-08 00:30:00"
>> [4] "2009-08-08 00:45:00" "2009-08-08 01:00:00"
>>



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. Received on Tue 29 Jun 2010 - 19:00:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jun 2010 - 19:20:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive