Current system time as a Timestamp
이전 댓글 표시
Hey,
I want to get the current system time in microseconds and share this timestamp with other computer via UDP. How to do that. fprintf('This message is sent at time %f', time) Is something like above possible in matlab? Please help me with this.
채택된 답변
추가 답변 (4개)
Ilham Hardy
2016년 1월 20일
fprintf('This message is sent at time %s\n', datestr(now,'HH:MM:SS.FFF'))
댓글 수: 2
PTP
2016년 1월 20일
Walter Roberson
2016년 1월 21일
No, you cannot get microseconds when you use datestr and now. The underlying representation is only accurate to less than 10 microseconds for times near this century. If you want to print the guaranteed inaccurate microseconds then you will need to format them yourself.
Jan
2016년 1월 21일
2 개 추천
A timestamp with a precision of microseconds is not meaningful, when the command to obtain the timestamp needs more than a microsecond. Then it is not exactly defined if the stamp belongs to the time before or after the command.
Walter Roberson
2016년 1월 21일
1 개 추천
No, this is not implemented by MATLAB. It is difficult to do, and the techniques are operating-system dependent.
Peter Perkins
2019년 3월 25일
1 개 추천
This is an old post the got reopened. I feel compelled to say that in anything like recent versions of MATLAB, datetime('now') is much preferred over now.
On Windows, the clock function and datetime('now') both return a system time rounded to milliseconds. On Linux or Mac, it's rounded to microseconds. Whether or not either of those is actually accurate or not depends entirely on your system though.
댓글 수: 2
Haoran WANG
2020년 3월 15일
Thank you for your hint. But how get microseconds system time in matlab in windows?
Walter Roberson
2020년 3월 18일
Haoran WANG : are you looking for clock time down to microsecond precision, or are you looking to create relative timings down to microsecond precision?
Getting the system clock down to microsecond is not easy. Microsoft says that for microseconds you should be querying the performance counters instead, but those are for relative times not for clock times.
For information on querying the performance counters in Windows see https://www.mathworks.com/matlabcentral/answers/37716-pause-function-in-matlab-for-1-millisecond#answer_97980
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!