View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Seconds to hours, minutes, seconds

3.2 | 4 ratings Rate this file 47 Downloads (last 30 days) File Size: 1.48 KB File ID: #22817 Version: 1.4

Seconds to hours, minutes, seconds


Simon Robinson (view profile)


29 Jan 2009 (Updated )

Converts a time in seconds to a time in hours, minutes and seconds.

| Watch this File

File Information

A very simple program to convert a time in seconds to a string giving the time in hours, minutes and seconds. Useful for producing readable toc output from programs which run for ages.


help secs2hms
 SECS2HMS - converts a time in seconds to a string giving the time in hours, minutes and second
 Example 1: >> secs2hms(7261)
 >> ans = 2 hours, 1 min, 1.0 sec
 Example 2: >> tic; pause(61); disp(['program took ' secs2hms(toc)]);
 >> program took 1 min, 1.0 secs


Tools For N If Ti And Analyze Image inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
14 Nov 2016 Bulk Masx

Helpful tool, thanks.

Comment only
24 Jun 2016 pankaj singh


11 Mar 2014 Pete

Pete (view profile)

I think much the same could be done with:

nSecs = 90;
datestr(nSecs/86400, 'HH:MM:SS.FFF')

Comment only
04 Feb 2009 Thorbjorn

Nice! This is useful for extended numerical calculations/ simulaitons. I have developed a similar function a while ago that I find useful (even simpler, but also faster than yours) -- will post it on the web.

30 Jan 2009 Jos (10584)

Jos (10584) (view profile)

should read: _NO_ H1 line ...

Comment only
30 Jan 2009 Jos (10584)

Jos (10584) (view profile)

This file contains H1 line , no help section and no comments, which makes it rather useless. First, how will you find the name of this file in the future if you cannot use LOOKFOR. Secondly, even if you find it, how will you know how to use it, if you cannot use HELP. Third, the total lack of comments makes it difficult to decipher what an end-user should do. In other words, it is only useful to someone with some matlab skills already. On the other hand, she or he will probably stick to something more matlab-ish like:

TimeInSecs = 7261 ;

29 Jan 2009 Husam Aldahiyat

Name is too long; have to manually change it to s2hms.
Other than that, pretty cool code.

02 Feb 2009 1.4

Function name shortened. H1 line and help added.

Contact us