Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
TI$none54 49 241.0+Reserved variable
* The "token" is really just the ASCII codes for the characters "TI$"

 Syntax 
TI$
 
ReturnsTypeValue(s)Note(s)
timeHMSString
6 digits:
000000 ~ 235959
HHMMSS format
(hours, minutes, seconds) 
 
 Purpose 
Get or Set the system time.
 
 Remarks 
This is the string version of the BASIC time variable.  The timeHMS is always a 6-character string.  Unlike all other reserved variables, this one may be assigned a value.  When not assigning a value (get the time), the timeHMS will always consist of numeric digits that range from 000000 to 235959 where the first two digits are hours (0~23), the middle two are the minutes (0~59), and the last two are the seconds (0~59).
 
In BASIC versions before 3.5, the timeHMS (when assigning) may include non-digits.  In such a case, the value of that "digit" would be calculated as ASC(digit)-48.  This gives the expected 0 ~ 9 for actual numeric digits, 10 for @, and 11 ~ 36 for unshifted letters A ~ Z (these are examples, any character is fine).  In versions 3.5 and beyond, attempts to use non-numeric digits generate ILLEGAL QUANTITY ERROR.
 
When assigning, if the seconds or minutes part of timeHMS exceed 59 then that part will be interpretted as zero (in version 1.0) or as value-60 (in versions 2+), and the next part (minutes or hours, respectively) will be increased by one.  If the hours part exceeds 23, then the system time is set to zero (000000), after a Jiffy (see examples).  In othe words, wrapping of values is broken in 1.0, and in other versions it works for seconds and minutes but not hours.
 
If you attempt to assign a string of not exactly 6 characters, ILLEGAL QUANTITY ERROR is generated.  Attempts to assign a numeric expression (a non-string) will generate TYPE MISMATCH ERROR.
 
This string version of the system time is only accurate to the nearest second, although the system time is mainted by a "Jiffy Clock" which has a maximum resolution of 1/60 second.  You can read this higher precision value with the numeric equivalant, TI, but you can not set that reserved variable.
 
Like all BASIC variables, only the first two characters of the name are significant.  So you may also use (and early documentation shows) TIME$ if you prefer (note the M and E are superfluous).
 
On most (all?) of the CBM 8-bits, the system time is mainted by software in the KERNAL, even though some machines have hardware which is more reliable.  In particular, delays in communicating with external devices (and a few internal operations) will cause the system time to "fall behind" reality (i.e., run slow).  Generally the more I/O operations that take place, the less reliable the system time.
 
The C128 has FAST and SLOW commands to change the CPU speed, and thus the speed of BASIC execution, but the Jiffy Clock works the same at either speed.
 
Unfortunately, none of the CBM BASICs have a DATE$ variable or function.  So you would need to periodically check the TI$ for "rollover" to detect a change in the date.
 
Example:
TI$ = "000000" : PRINT TI$
000000

READY.
TI$ = "000000" : FOR I = 1 TO 1000: NEXT : PRINT TI$
000001         value may vary a bit on different machines

READY.
TI$ = "000059" : FOR I = 1 TO 1000: NEXT : PRINT TI$
000100         value may vary a bit on different machines

READY.
TI$ = "000099" : PRINT TI$
000100         in V1.0 ~ or ~
000139         in V2+

READY.
TI$ = "00000A" : PRINT TI$
000017         in V1.0 ~ 2.x ~ or ~
?ILLEGAL QUANTITY ERROR   in V3.5+

READY.
TI$ = "239999" : PRINT TI$ : PRINT TI$
244039
000000

READY.
 
 Compare With 
 
 See Also 

© H2Obsession, 2014