Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Number of Seconds since 2000

    2D Blocks
    1
    1
    242
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Introduction

      In MIT Scratch, you can already manage dates using the “days since 2000” block. However, if you need a more granular control of date and time, you can use this new block:

      84a02f2c-9302-495d-9688-a909e3cfd49b-image.png

       

      This block will return the number of seconds that have passed between the given timestamp and the beginning of 2000.01.01.

       
       

      Input Format

       

      The input is a timestamp, which contains the date, a “T”, and then the time. The date is represented as year:month:day. The time is represented as hour:minute:second. Each field has to be 2 digits, except that the year has to be 4 digits.

      The timestamp is assumed to be the local time of the computer that’s running this program. If you want to use the UTC time, which is the same across the world, then append a “Z” at the end of the timestamp, such as “2024.01.01T10:00:00Z”.

      a03f7006-53e3-4b0a-96fa-299f6a71d685-image.png

      If the input is left empty, then the current time is used:

      84ac9740-6f1c-42b6-bb01-d49156e68cc8-image.png

       
       

      Calculating Time Difference

       

      With this new block, you can easily calculate how many seconds are between 2 timestamps. You just need to run this new block for both timestamps, then calculate the difference between them:

      b752552c-7bf4-440b-b9c7-d97d01def797-image.png

       
       

      Converting to Date

       

      You can also convert the number of seconds back to a Date object. For example, the program below first gets the number of seconds for a specific timestamp, then create a date object using that result, and we get the same timestamp as our input:

      5b827cfc-00b2-482b-8755-78c69995af2d-image.png

      1 Reply Last reply Reply Quote 2
      • First post
        Last post