Gold Award WinnerGold Award Winner

This article is about Clock object in Microsoft Small Basic programming language.

In this article:


What is a Clock

Personal computers have their internal (system) clock to know current date and time.

Clock Object

Clock object provides access to the system clock.  This object has properties only (no events, no operations) and they are for read only.

Properties

Clock object has 11 properties below.  These properties are for local time.  Especially, formats for Date, Time and WeekDay depend on the local language.

  • Date - the current system date
  • Day - the current day of the month
  • ElapsedMilliseconds - the number of milliseconds that have elapsed since 1900
  • Hour - the current hour
  • Millisecond - the current millisecond
  • Minute - the current minute
  • Month - the current month
  • Second - the current second
  • Time - the current system time
  • WeekDay - the current day of the week
  • Year - the current year

Sample Programs

Simple Demo for Clock Object

Source code:

TextWindow.WriteLine("Clock.Date=" + Clock.Date)
TextWindow.WriteLine("Clock.Day=" + Clock.Day)
TextWindow.WriteLine("Clock.ElapsedMilliseconds=" + Clock.ElapsedMilliseconds)
TextWindow.WriteLine("Clock.Hour=" + Clock.Hour)
TextWindow.WriteLine("Clock.Millisecond=" + Clock.Millisecond)
TextWindow.WriteLine("Clock.Minute=" + Clock.Minute)
TextWindow.WriteLine("Clock.Month=" + Clock.Month)
TextWindow.WriteLine("Clock.Second=" + Clock.Second)
TextWindow.WriteLine("Clock.Time=" + Clock.Time)
TextWindow.WriteLine("Clock.Weekday=" + Clock.WeekDay)
TextWindow.WriteLine("Clock.Year=" + Clock.Year)

Output:

Clock.Date=2016/01/02
Clock.Day=2
Clock.ElapsedMilliseconds=3660761508535.89
Clock.Hour=22
Clock.Millisecond=537
Clock.Minute=11
Clock.Month=1
Clock.Second=48
Clock.Time=22:11:48
Clock.Weekday=土曜日
Clock.Year=2016
Press any key to continue...

Sample Analog Clock

Program ID: SGP929-1. Following picture is the screen shot of this program.

Julian Day

Following code calculates current Julian Day (local time).  Julian Day is the elapsed days from the noon on January 1, 4713 BC (Julian calendar).

jd = Clock.ElapsedMilliseconds / 1000 / 3600 / 24 + 2415020.5

See Also

Other Resources