[R] any way to convert back to DateTime class when "accidental" conversion to numeric?

jim holtman jholtman at gmail.com
Thu Oct 6 03:12:00 CEST 2011


Here is what I use:

 unix2POSIXct(1317857320)
[1] "2011-10-05 19:28:40 EDT"


unix2POSIXct  <-  function (time) structure(time, class = c("POSIXt",
"POSIXct"))


On Wed, Oct 5, 2011 at 7:38 PM, Mike Williamson <this.is.mvw at gmail.com> wrote:
> Hi,
>
>    In short, I would like to know if there is any way to convert a numeric
> into a date, similar to how strptime() can convert a string to a date time
> class?
>
>    There are some functions, etc. which don't work well with dates, and
> tend to force them into numerics.  I understand that the number it spits
> back is the number of seconds since the beginning of 1970 (see the first few
> sentences of the "Details" portion of ?DateTimeClasses).
>    However, it's a bit of a hassle to convert that by hand.  I can create a
> function to do this, and it isn't so hard, but I found it hard to believe
> such a function didn't already exist, so I wanted to ask the community.
>
>    As an example, today (Oct 5th 2011 at approximately 4:30pm, Pacific
> time) is approximately 1317857320 as a numeric, but I would like to know how
> to go from that number back to the "2011-10-05 16:28:39 PDT" date time class
> which originally generated it.
>
>                        Thanks!
>                              Mike
>
> ---
> XKCD <http://www.xkcd.com>
>
>        [[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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list