convert seconds to time

조회 수: 107 (최근 30일)
Matlab Newbee
Matlab Newbee 2018년 1월 3일
댓글: Peter Perkins 2018년 11월 27일
Hi Team,
I have an array of numbers, which represents the number of seconds from 12am. Is there any way that I could convert seconds into time.
For example; 28225.6 is the number format I have, which is represents 28225.6 seconds after 12am. That is 7:50:25 AM in time.
Thank you

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 1월 3일
datestr(seconds(28225.6),'HH:MM:SS PM')
  댓글 수: 3
Anmar Mohammed
Anmar Mohammed 2018년 11월 26일
Thanks alot for sharing
Peter Perkins
Peter Perkins 2018년 11월 27일
Matlab Newbee, just so you know: there's probably no good reason to convert those durations (the array that seconds(28225.6) creates) to char. Unless all you want is a text representation for export outside of MATLAB, or maybe to annotate a plot, you would be shooting yourself in the foot. See my other response.

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

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 1월 5일
Unless you are using an older version of MATLAB, use durations:
>> seconds(28225.6)
ans =
duration
28225.6 sec
  댓글 수: 2
Matlab Newbee
Matlab Newbee 2018년 1월 8일
Thank you
Peter Perkins
Peter Perkins 2018년 1월 9일
From your other post, it looks like you'd probably want those to display as h:m:s. Either set the format after calling seconds, or just call duration.
>> s = seconds(28225.6)
s =
duration
28226 sec
>> s.Format = 'hh:mm:ss.SSS'
s =
duration
07:50:25.600
>> s = duration(0,0,28225.6)
s =
duration
07:50:25

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by