Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    TimeData

    The current time in variables: hours, minutes, seconds, weekday, date and a timestamp in milliseconds. Updated every tick . It is the basis for a greeting by time of day, a clock, a stopwatch and a timer.

    Type: single-child (its subtree sees the outputs)

    TimeData hour:@h minute:@m second:@s tick:1s
      Text $"${h}:${padLeft(m, 2, "0")}:${padLeft(s, 2, "0")}"

    Parameters

    Parameter Type Default Description
    tick duration ( 1s , 500ms , 1m ) 1m How often to update the outputs
    hour output @name — Hour, 0–23
    minute , second output @name — Minutes, seconds
    weekday output @name — Day of the week: 1 — Monday … 7 — Sunday
    day , month , year output @name — Date
    timestamp output @name — Milliseconds since the epoch, like now() : the basis of stopwatches and timers

    Declare only the outputs you need. On a tick only those whose value changed are notified: a clock with minute: redraws once a minute, even with tick:1s .

    On the site — the browser's clock

    On the site TimeData shows the browser's time: the outputs are written when the page loads and then on every tick. After a reload the time is right at once.

    Do not confuse it with now() in the initial value of state: State @clock:{now()} is evaluated when the page is built . On the site that is the server's time, and until the first update the page would show it. A clock is only TimeData .

    Timer

    Count from timestamps rather than accumulating ticks: then the accuracy does not depend on tick , and the timer survives a reload. On start, save the moment it ends; the remainder is the difference with timestamp :

    State @end:0
      TimeData timestamp:@ts tick:1s
        Column
          Text {end == 0 ? "1:30" : string(max(0, end - ts + 999) ~/ 60000) + ":" + padLeft(string((max(0, end - ts + 999) ~/ 1000) % 60), 2, "0")}
            #style fontSize:22 fontFeatures:["tnum"]
          ElevatedButton onPressed:(){end = now() + 90000}
            Text "Start 1:30"
    • fontFeatures:["tnum"] — digits of equal width: ticking seconds do not move their neighbours (see Text ).
    • To keep the timer between visits, hold end in Storage , not in State .
    • Put the ring at the end through `Sound at:` , not through a condition on now . A browser wakes the timers of a hidden tab once a minute, and the display there updates late, while Sound at: rings on time.

    See also

    • Sound — a sound at a scheduled moment ( at: )
    • Text — #style fontFeatures