umair durrani
umair durrani

Reputation: 6155

How to get milliseconds using as.POSIXct or as.POSIXlt in r?

I want to get subseconds so I use following:

> options(digits.secs=6)
> as.POSIXlt(df1$Global.Time[5]/1000, origin="1970-01-01",  tz="America/Los_Angeles")
[1] "2005-06-15 07:53:42.7 PDT"

Why does the output not contain something like "07:53:42.700000"?

Same problem with POSIXct:

> as.POSIXct(df1$Global.Time[3]/1000, origin="1970-01-01",  tz="America/Los_Angeles")
[1] "2005-06-15 07:53:42.5 PDT"

Upvotes: 3

Views: 2063

Answers (1)

Mike Wise
Mike Wise

Reputation: 22807

How about this (corrected per Frank's direction):

 d <- as.POSIXct(Sys.time())
 format(d,"%Y-%m-%d %H:%M:%OS6")
 [1] "2015-05-30 18:06:08.693852"

Upvotes: 7

Related Questions