Current ()
current [year v]
Category Sensing
Type Reporter
Introduced in v148 (2.0 alpha)

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, minute, or second, depending on the argument. The block gets the data based on the user's device's clock and it uses 24-hour time. 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 the two date/time blocks added in Scratch 2.0. The other is Days Since 2000, which reports the number of days since January 1, 2000.

It was originally called local () until v153 of Scratch 2.0, when it was renamed to current ().

Example Uses

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

  • Creating a clock or calendar
when gf clicked
set [calendar v] to (join (current [month v]) (join [/] (join (current [date v]) (join [/] (current [year v])))))
forever
if <<(current [minute v])<[10]> and <(current [second v])<[10]>> then
say (join (current [hour v]) (join [:0] (join (current [minute v]) (join [:0] (current [second v])))))
else
if <(current [minute v])<[10]> then
say (join (current [hour v]) (join [:0] (join (current [minute v]) (join [:] (current [second v])))))
else
if <(current [second v])<[10]> then
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:0] (current [second v])))))
else
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:] (current [second v])))))
  • Changing the background the as the day goes
when gf clicked
forever
if <<(current [hour v]) > [5]> and < (current [hour v]) < [12]>>  then // You can use any range of hours you feel that qualify as morning.  This is 6-11 o'clock.
switch backdrop to (Morning v)
else
if <<(current [hour v]) > [11]> and < (current [hour v]) < [18]>>  then // You can use any range of hours you feel that qualify as afternoon.  This is 12 - 17 o'clock.
switch backdrop to (Afternoon v)
else
switch backdrop to (Night v) // These hours are based on the previous hours.  This is 18 - 5 o'clock.
end
end
if <<(current [minute v])<[10]> and <(current [second v])<[10]>> then
say (join (current [hour v]) (join [:0] (join (current [minute v]) (join [:0] (current [second v])))))
else
if <(current [minute v])<[10]> then
say (join (current [hour v]) (join [:0] (join (current [minute v]) (join [:] (current [second v])))))
else
if <(current [second v])<[10]> then
say (join (current [hour v]) (join [:] (join (current [minute v]) (join [:0] (current [second v])))))
else
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]) < [2019]> then
  change [points v] by (1000)
else
  say [Sorry, but this feature is unavailable after 2018.]
end
  • Timestamps on a high-score list
if <(current [minute v])<[10]> then
add (join (join (join (join (join (join (join [Day:](current [date v]))[ ])(current [hour v]))[:0])(current [minute v]))[|Highscore:])(Score)) to [Highscores List v]
else
add (join (join (join (join (join (join (join [Day:](current [date v]))[ ])(current [hour v]))[:])(current [minute v]))[|Highscore:])(Score)) to [Highscores List v]
Note 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]))
else
set [hour v] to (current [hour v])
end
if <(current [minute v]) < [10]> then
set [minute v] to (join [0] (current [minute v]))
else
set [minute v] to (current [minute v])
end
if <(current [second v]) < [10]> then
set [second v] to (join [0] (current [second v]))
else
set [second v] to (current [second v])
end
say (join (hour) (join [:] (join (minute) (join [:] (second)))))

Workaround

The workaround used in Scratch 1.x is like this:

when gf clicked
reset timer
set [hour v] to []
set [minute v] to []
set [second v] to []
repeat until <<(hour)>[-1]> and <(hour)<[24]>>//hour>0 and hour<13 for 12hr clock
ask [What hour is it?] and wait
set [hour v] to (answer)
end
repeat until <<(minute)>[-1]> and <(minute)<[60]>>
ask [What minute is it?] and wait
set [minute v] to (answer)
end
reset timer
forever
set [second v] to (round ((timer)-(0.5)))//there was no floor or ceiling in scratch 1.x
if <(second)>[59]> then
reset timer
change [minute v] by (1)
end
if <(minute)>[59]> then
set [minute v] to [0]
change [hour v] by (1)
end
if <(hour)>[23]> then//hour>12 for 12hr clock
set [hour v] to [0]//set hour to 1 for 12hr clock
end

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.