How to convert UTC time to time in YEAR MONTH DAY HH MM SS?
UTC is 1263403529
I need
13-Jan-2012 17:25:29

 채택된 답변

C.J. Harris
C.J. Harris 2012년 3월 26일

0 개 추천

Grab the following file from the File Exchange:
Then call:
x = 1263403529;
y = datestr(utc2datenum(x));

댓글 수: 6

Jisha
Jisha 2012년 3월 26일
I get an error:
Attempt to execute SCRIPT utc2datenum as a function:
C.J. Harris
C.J. Harris 2012년 3월 26일
Ensure you have the 'utc2datenum.mexw32' file in the same location as 'utc2datenum.m'.
Jisha
Jisha 2012년 3월 26일
I do and the entire folder is on the MATLAB path.. it still gives me this error.. I have MATLAB 64 bit R2012a
C.J. Harris
C.J. Harris 2012년 3월 26일
Then that's your problem. MATLAB isn't recognising the '.mexw32' file since you are using a 64-bit version of MATLAB. You will have to recompile the source code in order to run it on your system.
Jisha
Jisha 2012년 3월 26일
Thanks..
Christoph Kessler
Christoph Kessler 2024년 2월 29일
What is the use if Answer requires a specific environment like 64 or 32-bit. Can you simply change without source code?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Steven Lord
Steven Lord 2018년 7월 27일

2 개 추천

You can do this using datetime.
>> dt = datetime(1263403529, 'ConvertFrom', 'posixtime')
dt =
datetime
13-Jan-2010 17:25:29
James Tursa
James Tursa 2012년 3월 26일

1 개 추천

If this is "seconds since 1970-01-01 00:00:00 TAI" it is more properly called "unix time" or "posix time" or sometimes "epoch time", not UTC. E.g., see this article:
If that is the case you can simply calculate your result as:
x = 1263403529;
e = datenum('01-jan-1970 00:00:00');
y = datestr(e+x/86400,'dd-mm-yyyy hh:mm:ss');

댓글 수: 4

C.J. Harris
C.J. Harris 2012년 3월 26일
For the format '13-Jan-2012 17:25:29' the last line would have to be:
y = datestr(e+x/86400,'dd-mmm-yyyy HH:MM:SS');
James Tursa
James Tursa 2012년 3월 26일
Oops. Thanks.
Geoff
Geoff 2012년 3월 26일
It's best to avoid string processing where it's not necessary:
e = datenum(1970,1,1,0,0,0);
James Tursa
James Tursa 2012년 3월 27일
Well, I would assume e would be a one-time only calculation in which case the string is more readable IMO. But if the goal is to make this calculation faster then I would simply eliminate it altogether. E.g.,
y = datestr(719529+x/86400,'dd-mmm-yyyy HH:MM:SS');
along with a comment stating where the magic number 719529 comes from.

댓글을 달려면 로그인하십시오.

Uilke Stelwagen
Uilke Stelwagen 2012년 5월 31일

1 개 추천

Wrote my own utc2datenum and discovered that 'UTC' 1263403529 is NOT "13-Jan-2012 17:25:29" but 1326475529 is. I.e. datestr(utc2datenum(1263403529)) = 13-Jan-2010 17:25:29, hence differing 2 years, while datestr(utc2datenum(1326475529)) = 13-Jan-2012 17:25:29. Best thing is to check a routine or algorithm with the 'UTC' time example given on http://en.wikipedia.org/wiki/Unix_time instead of starting with a wrong example.

댓글 수: 2

Dan
Dan 2012년 8월 12일
Current Wikipedia time is
1344541161 (2012-08-09 19:39:21Z)
>> utc = 1344541161
utc =
1.3445e+09
>> datestr(datenum([1970, 1, 1, 0, 0, utc]))
ans =
09-Aug-2012 19:39:21
I just blew everyone's mind...
marleen_ade
marleen_ade 2018년 7월 27일
perfect! Leave out the square brackets, and it works here too (R2015a 32 bit)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품

태그

질문:

2012년 3월 26일

댓글:

2024년 2월 29일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by