| Mapping Toolbox | ![]() |
Convert time to a clock string
Syntax
str = time2str(timein) str = time2str(timein,clock) str = time2str(timein,clock,format) str = time2str(timein,clock,format,units) str = time2str(timein,clock,format,digits) str = time2str(timein,clock,format,units,digits)
Description
The purpose of this command is to make time-valued variables into strings suitable for map display.
str = time2str(timein) converts a numerical vector of times to a string matrix. The output string matrix is useful for the display of times.
str = time2str(timein,clock) uses the specified clock input to construct the string matrix. Allowable clock strings are '24' (default) for a 24-hour clock, '12' for a 12-hour clock, and 'nav' for a navigational hour clock.
str = time2str(timein,clock,format) uses the specified format input to construct the string matrix. Allowable for format strings are 'hms', for hours, minutes, and seconds, and 'hm' (default), for hours and minutes.
str = time2str(timein,clock,format,units) defines the units in which the input times are supplied. Any valid time units string can be entered. If omitted, 'hours' is assumed.
str = time2str(timein,clock,format,digits) indicates the power of ten to be included for the seconds (if format = 'hms') or minutes (if format = 'hm'). The default value is 0, so nothing is returned to the right of the decimal (100 is the ones column). For example, if digits = -2, seconds would be returned down to the hundredths column.
Examples
13 hours, 56 minutes, 44 seconds in hms format is 1356.44.
For hm format, appropriate rounding occurs:
The 24-hour and navigational representations:
str = time2str(time,'24','hms','hms') str = 13:56:44 str = time2str(time,'nav','hms','hms') str = 1356'''
Navigational times are four digits; if seconds are included, they are rounded to the nearest 15 seconds, which are represented by tick marks (0=none, 15=', 30='', 45=''').
Consider the hms format time 1356.4456 for rounding purposes:
str = time2str(1356.4456,'12','hms','hms',-2) % hundredths str = 1:56:44.56 PM str = time2str(1356.4456,'12','hms','hms',-1) % tenths str = 1:56:44.6 PM
See Also
hr2hmshr2sec |
Other direct time conversion functions |
timedim |
Convert times between different units |
| tightmap | timedim | ![]() |