Converting timestamp from TDMS LabView
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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?
채택된 답변
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')
LD = struct with fields:
timestamp: [1124000x1 double]
format long
timestamp = LD.timestamp
timestamp = 1124000×1
1.0e+05 *
7.396442340758194
7.396442340758338
7.396442340758482
7.396442340758628
7.396442340758773
7.396442340758917
7.396442340759061
7.396442340759206
7.396442340759351
7.396442340759496
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Time24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='+02:00')
Time24 = 1124000x1 datetime array
01/27/2025 05:37:04.150
01/27/2025 05:37:04.152
01/27/2025 05:37:04.153
01/27/2025 05:37:04.154
01/27/2025 05:37:04.155
01/27/2025 05:37:04.157
01/27/2025 05:37:04.158
01/27/2025 05:37:04.159
01/27/2025 05:37:04.160
01/27/2025 05:37:04.162
01/27/2025 05:37:04.163
01/27/2025 05:37:04.164
01/27/2025 05:37:04.165
01/27/2025 05:37:04.167
01/27/2025 05:37:04.168
01/27/2025 05:37:04.169
01/27/2025 05:37:04.170
01/27/2025 05:37:04.172
01/27/2025 05:37:04.173
01/27/2025 05:37:04.174
01/27/2025 05:37:04.175
01/27/2025 05:37:04.177
01/27/2025 05:37:04.178
01/27/2025 05:37:04.179
01/27/2025 05:37:04.180
01/27/2025 05:37:04.182
01/27/2025 05:37:04.183
01/27/2025 05:37:04.184
01/27/2025 05:37:04.185
01/27/2025 05:37:04.187
LastLine24 = Time24(end)
LastLine24 = datetime
01/27/2025 06:00:29.149
TimeAP = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy hh:mm:ss.SSS a', TimeZone='+02:00')
TimeAP = 1124000x1 datetime array
01/27/2025 05:37:04.150 AM
01/27/2025 05:37:04.152 AM
01/27/2025 05:37:04.153 AM
01/27/2025 05:37:04.154 AM
01/27/2025 05:37:04.155 AM
01/27/2025 05:37:04.157 AM
01/27/2025 05:37:04.158 AM
01/27/2025 05:37:04.159 AM
01/27/2025 05:37:04.160 AM
01/27/2025 05:37:04.162 AM
01/27/2025 05:37:04.163 AM
01/27/2025 05:37:04.164 AM
01/27/2025 05:37:04.165 AM
01/27/2025 05:37:04.167 AM
01/27/2025 05:37:04.168 AM
01/27/2025 05:37:04.169 AM
01/27/2025 05:37:04.170 AM
01/27/2025 05:37:04.172 AM
01/27/2025 05:37:04.173 AM
01/27/2025 05:37:04.174 AM
01/27/2025 05:37:04.175 AM
01/27/2025 05:37:04.177 AM
01/27/2025 05:37:04.178 AM
01/27/2025 05:37:04.179 AM
01/27/2025 05:37:04.180 AM
01/27/2025 05:37:04.182 AM
01/27/2025 05:37:04.183 AM
01/27/2025 05:37:04.184 AM
01/27/2025 05:37:04.185 AM
01/27/2025 05:37:04.187 AM
LastLineAP = TimeAP(end)
LastLineAP = datetime
01/27/2025 06:00:29.149 AM
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
Maybe I didn't write my question properly. The original values were in timestamp.mat, attached to this question. I want to proses these values to get results as shown in the excel (column A).
Thanks, Star. Your results were still different from the one from Excel. The first line in Excel was 12:37:04.151, while you got it as 05:37:04.150793. Do you know the source of this difference? FYI, the measurement took place in GMT+2 time zone.
My pleasure!
I was going by the image, since that appeared to be what you wanted the dates and times to be. My first conversion code returned those results.
I corrected the time zones. You can change the seconds precision by changing the number of ‘S’ characters. I changed them back to three as well here, although in:
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
you specified at least four.
.
Thank, Star. I tried it on my computer using different timezones, but the results stayed the same. Did you experience this or not?
After experiimenting with it a bit, it now seems to be working.
I have no idea what the original problem was wiith it, however changing the TimeZone after creating the datetime array works, when including it as an argument does not (although it should, according to the documentation). Also, the time itself seems to have changed, since the original file had times beginning at 12:00 and this file begins at 05:00.
Try this —
LD = load('timestamp.mat')
LD = struct with fields:
timestamp: [1124000x1 double]
format long
timestamp = LD.timestamp
timestamp = 1124000×1
1.0e+05 *
7.396442340758194
7.396442340758338
7.396442340758482
7.396442340758628
7.396442340758773
7.396442340758917
7.396442340759061
7.396442340759206
7.396442340759351
7.396442340759496
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
OriginalTime24 = datetime(timestamp, ConvertFrom='datenum', Format='MM/dd/yyyy HH:mm:ss.SSS', TimeZone='Z')
OriginalTime24 = 1124000x1 datetime array
01/27/2025 05:37:04.150
01/27/2025 05:37:04.152
01/27/2025 05:37:04.153
01/27/2025 05:37:04.154
01/27/2025 05:37:04.155
01/27/2025 05:37:04.157
01/27/2025 05:37:04.158
01/27/2025 05:37:04.159
01/27/2025 05:37:04.160
01/27/2025 05:37:04.162
01/27/2025 05:37:04.163
01/27/2025 05:37:04.164
01/27/2025 05:37:04.165
01/27/2025 05:37:04.167
01/27/2025 05:37:04.168
01/27/2025 05:37:04.169
01/27/2025 05:37:04.170
01/27/2025 05:37:04.172
01/27/2025 05:37:04.173
01/27/2025 05:37:04.174
01/27/2025 05:37:04.175
01/27/2025 05:37:04.177
01/27/2025 05:37:04.178
01/27/2025 05:37:04.179
01/27/2025 05:37:04.180
01/27/2025 05:37:04.182
01/27/2025 05:37:04.183
01/27/2025 05:37:04.184
01/27/2025 05:37:04.185
01/27/2025 05:37:04.187
OT24TZ = OriginalTime24.TimeZone
OT24TZ = '+00:00'
NewTime1 = OriginalTime24;
NT1TZ = NewTime1.TimeZone
NT1TZ = '+00:00'
TZ = '+02:00';
NewTime1.TimeZone = TZ
NewTime1 = 1124000x1 datetime array
01/27/2025 07:37:04.150
01/27/2025 07:37:04.152
01/27/2025 07:37:04.153
01/27/2025 07:37:04.154
01/27/2025 07:37:04.155
01/27/2025 07:37:04.157
01/27/2025 07:37:04.158
01/27/2025 07:37:04.159
01/27/2025 07:37:04.160
01/27/2025 07:37:04.162
01/27/2025 07:37:04.163
01/27/2025 07:37:04.164
01/27/2025 07:37:04.165
01/27/2025 07:37:04.167
01/27/2025 07:37:04.168
01/27/2025 07:37:04.169
01/27/2025 07:37:04.170
01/27/2025 07:37:04.172
01/27/2025 07:37:04.173
01/27/2025 07:37:04.174
01/27/2025 07:37:04.175
01/27/2025 07:37:04.177
01/27/2025 07:37:04.178
01/27/2025 07:37:04.179
01/27/2025 07:37:04.180
01/27/2025 07:37:04.182
01/27/2025 07:37:04.183
01/27/2025 07:37:04.184
01/27/2025 07:37:04.185
01/27/2025 07:37:04.187
NT1TZ = NewTime1.TimeZone
NT1TZ = '+02:00'
NewTime2 = OriginalTime24;
NT2TZ = NewTime2.TimeZone
NT2TZ = '+00:00'
TZ = '-07:00';
NewTime2.TimeZone = TZ
NewTime2 = 1124000x1 datetime array
01/26/2025 22:37:04.150
01/26/2025 22:37:04.152
01/26/2025 22:37:04.153
01/26/2025 22:37:04.154
01/26/2025 22:37:04.155
01/26/2025 22:37:04.157
01/26/2025 22:37:04.158
01/26/2025 22:37:04.159
01/26/2025 22:37:04.160
01/26/2025 22:37:04.162
01/26/2025 22:37:04.163
01/26/2025 22:37:04.164
01/26/2025 22:37:04.165
01/26/2025 22:37:04.167
01/26/2025 22:37:04.168
01/26/2025 22:37:04.169
01/26/2025 22:37:04.170
01/26/2025 22:37:04.172
01/26/2025 22:37:04.173
01/26/2025 22:37:04.174
01/26/2025 22:37:04.175
01/26/2025 22:37:04.177
01/26/2025 22:37:04.178
01/26/2025 22:37:04.179
01/26/2025 22:37:04.180
01/26/2025 22:37:04.182
01/26/2025 22:37:04.183
01/26/2025 22:37:04.184
01/26/2025 22:37:04.185
01/26/2025 22:37:04.187
NT2TZ = NewTime2.TimeZone
NT2TZ = '-07:00'
Use the formats for either 24 Hour time or AM/PM time, as you prefer.
To do that —
NewTime1
NewTime1 = 1124000x1 datetime array
01/27/2025 07:37:04.150
01/27/2025 07:37:04.152
01/27/2025 07:37:04.153
01/27/2025 07:37:04.154
01/27/2025 07:37:04.155
01/27/2025 07:37:04.157
01/27/2025 07:37:04.158
01/27/2025 07:37:04.159
01/27/2025 07:37:04.160
01/27/2025 07:37:04.162
01/27/2025 07:37:04.163
01/27/2025 07:37:04.164
01/27/2025 07:37:04.165
01/27/2025 07:37:04.167
01/27/2025 07:37:04.168
01/27/2025 07:37:04.169
01/27/2025 07:37:04.170
01/27/2025 07:37:04.172
01/27/2025 07:37:04.173
01/27/2025 07:37:04.174
01/27/2025 07:37:04.175
01/27/2025 07:37:04.177
01/27/2025 07:37:04.178
01/27/2025 07:37:04.179
01/27/2025 07:37:04.180
01/27/2025 07:37:04.182
01/27/2025 07:37:04.183
01/27/2025 07:37:04.184
01/27/2025 07:37:04.185
01/27/2025 07:37:04.187
NewTime1AMPM = NewTime1;
NewTime1AMPM.Format = 'MM/dd/yyyy hh:mm:ss.SSS a'
NewTime1AMPM = 1124000x1 datetime array
01/27/2025 07:37:04.150 AM
01/27/2025 07:37:04.152 AM
01/27/2025 07:37:04.153 AM
01/27/2025 07:37:04.154 AM
01/27/2025 07:37:04.155 AM
01/27/2025 07:37:04.157 AM
01/27/2025 07:37:04.158 AM
01/27/2025 07:37:04.159 AM
01/27/2025 07:37:04.160 AM
01/27/2025 07:37:04.162 AM
01/27/2025 07:37:04.163 AM
01/27/2025 07:37:04.164 AM
01/27/2025 07:37:04.165 AM
01/27/2025 07:37:04.167 AM
01/27/2025 07:37:04.168 AM
01/27/2025 07:37:04.169 AM
01/27/2025 07:37:04.170 AM
01/27/2025 07:37:04.172 AM
01/27/2025 07:37:04.173 AM
01/27/2025 07:37:04.174 AM
01/27/2025 07:37:04.175 AM
01/27/2025 07:37:04.177 AM
01/27/2025 07:37:04.178 AM
01/27/2025 07:37:04.179 AM
01/27/2025 07:37:04.180 AM
01/27/2025 07:37:04.182 AM
01/27/2025 07:37:04.183 AM
01/27/2025 07:37:04.184 AM
01/27/2025 07:37:04.185 AM
01/27/2025 07:37:04.187 AM
NewTime2
NewTime2 = 1124000x1 datetime array
01/26/2025 22:37:04.150
01/26/2025 22:37:04.152
01/26/2025 22:37:04.153
01/26/2025 22:37:04.154
01/26/2025 22:37:04.155
01/26/2025 22:37:04.157
01/26/2025 22:37:04.158
01/26/2025 22:37:04.159
01/26/2025 22:37:04.160
01/26/2025 22:37:04.162
01/26/2025 22:37:04.163
01/26/2025 22:37:04.164
01/26/2025 22:37:04.165
01/26/2025 22:37:04.167
01/26/2025 22:37:04.168
01/26/2025 22:37:04.169
01/26/2025 22:37:04.170
01/26/2025 22:37:04.172
01/26/2025 22:37:04.173
01/26/2025 22:37:04.174
01/26/2025 22:37:04.175
01/26/2025 22:37:04.177
01/26/2025 22:37:04.178
01/26/2025 22:37:04.179
01/26/2025 22:37:04.180
01/26/2025 22:37:04.182
01/26/2025 22:37:04.183
01/26/2025 22:37:04.184
01/26/2025 22:37:04.185
01/26/2025 22:37:04.187
NewTime2AMPM = NewTime2;
NewTime2AMPM.Format = 'MM/dd/yyyy hh:mm:ss.SSS a'
NewTime2AMPM = 1124000x1 datetime array
01/26/2025 10:37:04.150 PM
01/26/2025 10:37:04.152 PM
01/26/2025 10:37:04.153 PM
01/26/2025 10:37:04.154 PM
01/26/2025 10:37:04.155 PM
01/26/2025 10:37:04.157 PM
01/26/2025 10:37:04.158 PM
01/26/2025 10:37:04.159 PM
01/26/2025 10:37:04.160 PM
01/26/2025 10:37:04.162 PM
01/26/2025 10:37:04.163 PM
01/26/2025 10:37:04.164 PM
01/26/2025 10:37:04.165 PM
01/26/2025 10:37:04.167 PM
01/26/2025 10:37:04.168 PM
01/26/2025 10:37:04.169 PM
01/26/2025 10:37:04.170 PM
01/26/2025 10:37:04.172 PM
01/26/2025 10:37:04.173 PM
01/26/2025 10:37:04.174 PM
01/26/2025 10:37:04.175 PM
01/26/2025 10:37:04.177 PM
01/26/2025 10:37:04.178 PM
01/26/2025 10:37:04.179 PM
01/26/2025 10:37:04.180 PM
01/26/2025 10:37:04.182 PM
01/26/2025 10:37:04.183 PM
01/26/2025 10:37:04.184 PM
01/26/2025 10:37:04.185 PM
01/26/2025 10:37:04.187 PM
Success!
.
Thanks, Star! I realy appreciate your effort to help me! I just knew that we can twist the time zone after creating datetime!
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개)
카테고리
도움말 센터 및 File Exchange에서 Standard File Formats에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
