Q(uick)BASIC Function: TIME$
Quick View
TIME$
A function that returns the current time from the operating system
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- TIME$
- TIME$ = stringexpression$
Description/Parameter(s)
- The TIME$ function returns the computer's current system time.
- The TIME$ statement sets the current system time on your computer.
stringexpression$ | The time in one of the following forms: | |||||
|
||||||
The TIME$ function returns a string in the form hh:mm:ss. |
Example
PRINT TIME$
TIME$ = "08:00:58" 'Note: The new system time remains in effect until
' you change it again.
PRINT "Time set to "; TIME$
See also:
Syntax
- TIME$
Description/Parameter(s)
- an eight-character string is returned, in the form hh:mm:ss
hh is the hour (00-23),
mm is the minute (00-59), and
ss is the second (00-59)
The TIME$ function returns an eight-character string in the pattern hh:mm:ss, where hh is the hour (00-23), mm is minutes (00-59), and ss is seconds (00-59). A 24-hour clock is used; therefore, 8:00 PM is shown as 20:00:00.
To set the time, use the TIME$ statement.
Example
The following example converts the 24-hour time returned by TIME$ to a 12-hour time.
'Convert the 24-hour clock used by TIME$ to
'12-hour output followed by "AM" or "PM."
T$ = TIME$
Hr = VAL(T$)
IF Hr < 12 THEN Ampm$ = " AM" ELSE Ampm$ = " PM"
IF Hr > 12 THEN Hr = Hr - 12
PRINT "The time is" STR$(Hr) RIGHT$(T$,6) Ampm$
Sample Output:
The time is 11:26:31 AMSee also:
Syntax
- TIME$
Description/Parameter(s)
The current time from the operating system as an 8-character string in the form hh:mm:ss where: | |
hh | Is the hour (00-23). |
mm | Is the minute (00-59). |
ss | Is the second (00-59). |
Usage Notes
- A 24-hour clock is used; therefore, 8:00 P.M. is shown as 20:00:00.
- To set the time, use the TIME$ statement.
Example
This example converts the 24-hour clock used by the TIME$ function to 12-hour output followed by "AM" or "PM."
T$ = TIME$
Hr = VAL(T$)
IF Hr < 12 THEN Ampm$ = " AM" ELSE Ampm$ = " PM"
IF Hr > 12 THEN Hr = Hr - 12
PRINT "The time is"; STR$(Hr); RIGHT$(T$, 6); Ampm$
Sample Output:
The time is 11:26:31 AMSee also: