Usage of Scratch's "days from 2000 to the present" building blocks

Number of days since 2000

Number of days since 2000

It seems that this building block is useless. The year 2000 is still a fixed value and cannot be entered. Click it, and you can see that a number with a particularly large number of decimal places is returned.

But in fact, this building block has many functions. This brick is used in many homemade brick kits. Next, I demonstrate the function of this building block.


1. Calculate precise time (hour, minute, second, millisecond, etc.)

The formula is as follows:

        [Number of days from 2000 to the present × the advance rate of the unit’s first grade and day - rounded down (the number of days since 2000 × the advance rate of the unit’s grade and day)] × the advance rate of the unit and the unit of the next grade

        Is it a little difficult to understand, never mind, let's look at an example.

        We require precise seconds. The unit one level larger than seconds is minutes. The rate of minutes and seconds is 60, and the rate of minutes and days is 1440 (24×60). Then, when substituted into the formula, it becomes the following .

        Compared with the seconds of the current time, it can be seen that it is indeed more accurate. The principle is to calculate the number of seconds first, (round down to get the decimal part) and then multiply by 60 to get the exact number of seconds. However, one thing to note is that the precise time already includes the time of the next level, so it is not possible to have precise minutes and precise seconds. This is incorrect, so it is recommended to be accurate only at the last digit.


2. Never stop

        As we all know, the timer in Scratch3 will reset to zero every time the green flag is clicked, regardless of whether the timer reset block is running or not. But the number of days from 2000 to the present will not, it will never stop, closing the work and opening it will not affect it, and it can also be connected across works. And the precision is super high. According to my test, it can be accurate to microseconds, but not to nanoseconds. The formula is as follows:

        The number of days from 2000 to the present × the rate of days and the unit you want

        If we ask for the number of microseconds from 2000 to the present, we can ask for it like this:

The calculation formula of microseconds from 2000 to the present (1000000 is the rate of microseconds and seconds)

        The calculation formula of microseconds from 2000 to the present (1000000 is the rate of microseconds and seconds)

        In addition, this building block returns UTC standard time, which has an 8-hour time difference (UTC+8) from Beijing time, so if you use it to calculate time, you need to add 8 hours to get Beijing time.


3. My idea

        Since works can be crossed, such a program can be made: when the number of days from 2000 to the present is greater than a number, many works will trigger a specific program at the same time (such as the countdown to the new year)

        Also, I'm curious, if the computer's time is changed to less than 2000, will this block return a positive or negative number?

Guess you like

Origin blog.csdn.net/leyang0910/article/details/131999440