[R] Change date time to epoch time

David Winsemius dwinsemius at comcast.net
Sun Nov 17 04:15:15 CET 2013


On Nov 16, 2013, at 8:46 PM, vivek kumar singh wrote:

> Hi All,
>
> I have time series data in (Year-month-date-hour-minute-second) format
> and i want to convert it to epoch time.
>
> I have tried the following:
> *> Sys.time()**
> **[1] "2013-11-17 10:39:46 MYT"**
> **> as.numeric(Sys.time())**
> **[1] 1384656006**

Should we assume this is "epoch time"?

> **> as.numeric("2013-11-17 10:39:46 MYT")**
> **[1] NA**
> **Warning message:**
> **NAs introduced by coercion **
> **> as.numeric("2013-11-17 10:39:46 MYT")**
> **[1] NA**

If it is then this is close:

as.numeric(as.POSIXct("2013-11-17 10:39:46 MYT"))

(You may need to supply an appropriate TZ offset in seconds

?POSIXct


--  
David.

> **Warning message:**
> **NAs introduced by coercion **
> *
> Please let me know which function in R converts date-time to epoch  
> time.
>
> Regards,
> Vivek
>
> 	[[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
Alameda, CA, USA



More information about the R-help mailing list