openlang

Getting Godot system time for a digital clock?

I'm building a digital clock for my game, so I need the present time (hours and minutes) displayed like this: HH:MM:SS Where do I obtain the time values to do that?

The conversation continues 2

Follow the reasoning
  1. Permalink

    The Time (https://docs.godotengine.org/en/stable/classes/class_time.html) singleton provides get_datetime_dict_from_system (https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-datetime-dict-from-system), which gives you a dictionary containing time information obtained from the system clock.

    # Read a dictionary of clock fields
    var clock_fields = Time.get_time_dict_from_system()
    
    print(clock_fields) # {day:X, dst:False, hour:xx, minute:xx, month:xx, second:xx, weekday:x, year:xxxx}

    For your HH:MM formatting, the simpler get_time_dict_from_system (https://get_time_dict_from_system) gives just the hour, minute and second fields

    var clock_fields = Time.get_time_dict_from_system()
    
    # Format each field with 2 zero-padded digits, e.g. 02:31:24
    print("%02d:%02d:%02d" % [clock_fields.hour, clock_fields.minute, clock_fields.second])

    On earlier Godot releases (-3.4), you can also call OS.get_time() (https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-get-time), though it is deprecated in 3.5+ and gone in 4.x:

Other sides of the same question

  1. Can gdb set a breakpoint for an assembly instruction using its address?

    My attempt: apparently this command does not exist, though. Can gdb do something like this?

    Replies 2Latest activity assembly
  2. Can Playwright assertions allow either of two possible text values?

    I'd like to verify that the text contains either one or two: Can this be made to work in Playwright? Could the same thing als…

    Replies 2Latest activity typescript
  3. Why is TsLint requesting a return type for this function's callSignature?

    My code includes the following function: TsLint reports this error for it: Could somebody clarify the message for me?

    Replies 2Latest activity typescript