Converting timestamp from TDMS LabView
13 ビュー (過去 30 日間)
古いコメントを表示
I received measurement data using LabView as a TDMS file and use TDMS reader from https://se.mathworks.com/matlabcentral/fileexchange/30023-tdms-reader to import it. The file name itself already indicated date and time of the measurement, e.g., COP_meas1_25-01-27_1237.tdms, but the resolution was only 1 s.
Using excel with AddOn from NI, I got the following results:

From values attached to this question.
Using
datetime(timestamp(1:5),'ConvertFrom','datenum','TicksPerSecond',1e4,'Format','HH:mm:ss.SSSS')
I got the following results.
05:37:04.1507
05:37:04.1520
05:37:04.1532
05:37:04.1545
05:37:04.1557
Using
datetime(timestamp(1),'ConvertFrom','posixtime')
I got
09-Jan-1970 13:27:24
I have tried using various combinations but I failed. How should I use the parameters to get the same results as in Excel?
0 件のコメント
採用された回答
Star Strider
2025 年 1 月 29 日
編集済み: Star Strider
2025 年 1 月 29 日
I did not see the .mat file before, although I did look for it.
Try this —
LD = load('timestamp.mat')
format long
timestamp = LD.timestamp
Time24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='+02:00')
LastLine24 = Time24(end)
TimeAP = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy hh:mm:ss.SSS a', TimeZone='+02:00')
LastLineAP = TimeAP(end)
I prefer 24-hour time. I posted conversions for both here.
I am not certain what sort of resolution you want (or what the data provide). I have them in µs here. Append more ‘S’ characters to get additional displayed precision.
The Format name-value pair determines how the datetime values are displayed. It keeps full internal precision regardless.
EDIT — (29 Jan 2025 at 13:22)
Adeded timestamp.mat file import and changed the datetime calls to accommodate it.
EDIT — (29 Jan 2025 at 14:42)
Corrected (added) time zone offset, changed seconds resolution from 6 to 3 (µs to ms). .
.
7 件のコメント
Star Strider
2025 年 1 月 30 日
As always, my pleasure!
The solution was defining the TimeZone of the original as 'Z' (or equivalently, 'UTC'), although I thought that was the default. After that, defining the other time zones is straightforward.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!