From Test-Scratch-Wiki

Current ()
2.0 Current ().png
Category Sensing
Type Reporter
Introduced in 2.0

The Current () block is a Sensing block and a reporter block. It reports either the current local year, month, date, day of the week, hour, minutes, or seconds, depending on the argument. The block gets the data based on the user's computer's clock and set in 24-hour clock. The block was previously called Local () in early versions of the Scratch 2.0 alpha to make it clearer that it uses a user's local time.

The options in Current ().

It is one of two new date/time blocks in Scratch 2.0 so far. The other is Days Since 2000, which reports the amount of days since January 1, 2000.

Example Uses

This block can be used in some of the following ways:

  • Creating a clock or calendar
when gf clicked
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:] (current [second v])))))
  • Making something unavailable before or after a certain date
if <(current [year v]) < [2015]> then
  change [money v] by (1000)
  say [Sorry, but this feature is unavailable after 2014.]
  • Timestamps on a high-score list
add (join (join (join (join (join (join (join [Day:](current [day v]))[ ])(current [hour v]))[:])(current [minute v]))[|Highscore:])(Score)) to [Highscores List v]

Note: When the output is less than 10, the hour, minute, and second blocks will report a single-digit unpadded number instead of a double-digit number, e.g. 05:09:03 will appear as 5:9:3.

This can be corrected with the following script:

if <(current [hour v]) < (10)> then
set [hour v] to (join (0) (current [hour v]))
set [hour v] to (current [hour v])
if <(current [minute v]) < (10)> then
set [minute v] to (join (0) (current [minute v]))
set [minute v] to (current [minute v])
if <(current [second v]) < (10)> then
set [second v] to (join (0) (current [second v]))
set [second v] to (current [second v])
say (join (hour) (join [:] (join (minute) (join [:] (second)))))

See Also

Days Since 2000