Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse milliseconds?

How do I use strptime or any other functions to parse time stamps with milliseconds in R?

time[1] # [1] "2010-01-15 13:55:23.975" strptime(time[1], format="%Y-%m-%d %H:%M:%S.%f") # [1] NA strptime(time[1], format="%Y-%m-%d %H:%M:%S") # [1] "2010-01-15 13:55:23"` 
like image 460
signalseeker Avatar asked Jan 27 '10 20:01

signalseeker


People also ask

How do you format milliseconds?

In the Format Cells window, go to the Number tab, select Custom from the Category list, and enter h:mm:ss. 000 in the Type text box. As a result, all of the time values are displayed with milliseconds as decimals.

How do you convert milliseconds to date time?

Approach : First declare variable time and store the milliseconds of current date using new date() for current date and getTime() Method for return it in milliseconds since 1 January 1970. Convert time into date object and store it into new variable date. Convert the date object's contents into a string using date.


1 Answers

Courtesy of the ?strptime help file (with the example changed to your value):

 z <- strptime("2010-01-15 13:55:23.975", "%Y-%m-%d %H:%M:%OS")  z # prints without fractional seconds  op <- options(digits.secs=3)  z  options(op) #reset options 
like image 77
Aniko Avatar answered Oct 09 '22 08:10

Aniko