datenum to UTC?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi, I have
10-Oct-2013 15:59:00
and I need UTC time
1381435140
Is there any easy way? (time zone GTM-4)
Thanks!
댓글 수: 1
Guillaume
2018년 10월 25일
That's not UTC time, that's a Unix Time Stamp
It also appears that your input is a datetime not a datenum.
채택된 답변
James Tursa
2018년 10월 25일
편집: James Tursa
2018년 10월 25일
Are you just looking for how to convert from the former to the latter? E.g.,
s = '10-Oct-2013 15:59:00';
unix_m4 = (datenum(s) - datenum('01-Jan-1970'))*86400 + 4*3600;
or
unix_m4 = seconds((datetime(s) - datetime('01-Jan-1970')) + seconds(4*3600));
or
unix_m4 = seconds(datetime(s,'timezone','-4') - datetime('01-Jan-1970','timezone','UTC'));
This result isn't called UTC btw, it is called Unix time:
추가 답변 (1개)
jonas
2018년 10월 25일
편집: jonas
2018년 10월 25일
Yes, use datetime instead of datenum.
t = datetime('10-Oct-2013 15:59:00','timezone','-04:00')
t_unix = posixtime(t)
댓글 수: 1
Peter Perkins
2018년 10월 31일
'-04:00' is a valid time zone, but perhaps a little dangerous. It's a time zone that does not observe4 DST. If the OP is in, say, Boston, then that would give the wrong answer for 10-Nov. Something like 'America/New_York' is probably the right choice.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!