我在给游戏制作数字时钟,需要把当前时间(小时和分钟)显示成 HH:MM:SS 这样的格式。应该从哪里取得所需的时间值?
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?
我在给游戏制作数字时钟,需要把当前时间(小时和分钟)显示成 HH:MM:SS 这样的格式。应该从哪里取得所需的时间值?
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?
Time (https://docs.godotengine.org/en/stable/classes/class_time.html) 单例提供 get_datetime_dict_from_system (https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-datetime-dict-from-system),它会返回一个字典,包含从系统时钟取得的时间信息。
# 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}
对于你的 HH:MM 格式,更简单的 get_time_dict_from_system (https://get_time_dict_from_system) 只返回小时、分钟和秒字段
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])
在较早的 Godot 版本(-3.4)中,也可以调用 OS.get_time() (https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-get-time),但它在 3.5+ 中已弃用,在 4.x 中已移除。
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:
在 Godot 4.x 中,Time.get_time_string_from_system() (https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-time-string-from-system) 会返回系统时钟的时间字符串,格式已经是 HH:MM:SS。
With Godot 4.x, Time.get_time_string_from_system() (https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-time-string-from-system) gives the system clock time as a string already using the HH:MM:SS format.
我的尝试如下。 不过,看起来并不存在这条命令。 gdb 能实现这样的功能吗?
我想验证文本中包含 one 或 two。 在 Playwright 中能这样实现吗? 同样的写法也能用在句子内部吗,比如下面这样
我的代码中有下面这个函数。 TsLint 对它报告了这个错误。 有人能解释一下这条消息的含义吗?