Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R current time in milliseconds

Tags:

r

How can I get the current time in milliseconds? I tried the below without success:

> strptime(Sys.time(), "%Y-%m-%d %H:%M:%OS")
[1] "2022-05-14 19:42:53 CEST
like image 775
gaut Avatar asked Sep 16 '25 17:09

gaut


2 Answers

You do get milliseconds by default on all operating systems, and (almost as the effective resolution is just a fraction less) microseconds on Linux and macOS -- but you must enable the printing of it.

Default R behaviour

> options(digits.secs=0) 
> Sys.time()             
[1] "2022-05-14 13:01:57 CDT" 
> 

Changed to Six Digits

> options(digits.secs=6)
> Sys.time()
[1] "2022-05-14 13:02:54.038276 CDT"
> 

I actually set this in my default ~/.Rprofile to always have six decimals.

like image 112
Dirk Eddelbuettel Avatar answered Sep 19 '25 06:09

Dirk Eddelbuettel


format(Sys.time(), "%Y-%m-%d %H:%M:%OS3")

#[1] "2022-05-14 11:01:17.928"
like image 34
Jon Spring Avatar answered Sep 19 '25 06:09

Jon Spring