FormatTime$() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Returns a string representing a time using the format specified in the second argument. You can call this function from the MapBasic window in MapInfo Pro.

Note: The FormatDate$() function is not configurable whereas the FormatTime$() function provides full control of the output.

Syntax

FormatTime$( time, string )

time is the time value.

string is the format to use for the return string value (see description section).
Note: If the string parameter is passed as empty, MapInfo Pro time format would be the default time format.

Return Value

String

Description

The string format should follow the same Microsoft standards as for setting the locale time format:

Hours Meaning
h Hours without leading zeros for single-digit hours (12-hour clock).
hh Hours with leading zeros for single-digit hours (12-hour clock).
H Hours without leading zeros for single-digit hours (24-hour clock).
HH Hours with leading zeros for single-digit hours (24-hour clock).
Minutes Meaning
m Minutes without leading zeros for single-digit minutes.
mm Minutes with leading zeros for single-digit minutes.
Seconds Meaning
s Seconds without leading zeros for single-digit seconds.
ss Seconds with leading zeros for single-digit seconds.
Time marker Meaning
t One-character time marker string.
Note: Do not to use this format for certain languages, for example, Japanese (Japan). With this format, the application always takes the first character from the time marker string, defined by LOCALE_S1159 (AM) and LOCALE_S2359 (PM). Because of this, the application can create incorrect formatting with the same string used for both AM and PM.
tt Multi-character time marker string.

Source: https://msdn.microsoft.com/en-us/library/dd318148.aspx

In the preceding formats, the letters m, s, and t must be lowercase, and the letter h must be lowercase to denote the 12-hour clock or uppercase to denote the 24-hour clock.

Our code follows the rules for specifying the system local time format. In addition, we also allow the user to specify f, ff, or fff for tenths of a second, hundredths of a second, or milliseconds.

Example

Copy this example into the MapBasic window for a demonstration of this function.

dim Z as time
Z = CurTime()
Print FormatTime$(Z, "hh:mm:ss.fff tt")

See Also:

Date and Time Functions, FormatDate$() function, GetTime() function, NumberToDateTime() function