[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] Help with simple as.POSIXlt or strptime
From:       Jim Lemon <jim () bitwrit ! com ! au>
Date:       2013-09-29 2:12:28
Message-ID: 52478C8C.6050505 () bitwrit ! com ! au
[Download RAW message or body]

On 09/29/2013 01:27 AM, Leopoldo Catania wrote:
> Hi,
> I really don't know what is wrong with my code, I have a character object
> and I need to have a POSIXlt object; my code is:
>> date="Mon, 23 Sep 2013 06:45:05 GMT"
>> as.POSIXlt(date,format="%a, %d %b %Y %H:%M:%S %Z")
> [1] NA
> even with
>> strptime(date,"%a, %d %b %Y %H:%M:%S %Z")
> [1] NA
> Also if I remove "Mon," and "GMT"
>> date2="23 Sep 2013 06:45:05"
>> as.POSIXlt(date2,format="%d %b %Y %H:%M:%S")
> [1] NA
>> strptime(date2,format="%d %b %Y %H:%M:%S")
> [1] NA
> If I try to run the last code line in ?strptime the result is:
> ## An RFC 822 header (Eastern Canada, during DST)
> strptime("Tue, 23 Mar 2010 14:36:38 -0400",  "%a, %d %b %Y %H:%M:%S %z")
> [1] NA
>
Hi Leopoldo,
The %Z is only included in the format string for output. Try these:

strptime(date,"%a, %d %b %Y %H:%M:%S")
[1] "2013-09-23 06:45:05"
strptime(date,"%a, %d %b %Y %H:%M:%S",tz="GMT")
[1] "2013-09-23 06:45:05 GMT"

Jim

______________________________________________
R-help@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.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic