Updated example to show timestamp customization

Also updated the code to make ampm invisible unless 12hour specified
(So if you forgot 24hour can't support AM or PM indicators)
This commit is contained in:
david 2021-09-04 23:58:19 -04:00
parent 94bda86a8c
commit 65711566e1
2 changed files with 7 additions and 5 deletions

View File

@ -17,5 +17,5 @@ func _ready():
printerr("This only goes to the console")
# Logger also includes some assistant functions
print("Current datetime stamp: ", Log.timestamp()) # This is used internally by Logger itself
print("Current datetime stamp: ", Log.timestamp("{month}/{day}/{year} {12hour}:{min}:{sec} {ampm}")) # I.E. '01/01/2000 01:53:22 AM'
print("Position of Example Logging node: ", Log.pos2str(self.position)) # This is so you can print positions

View File

@ -44,10 +44,12 @@ func pos2str(pos: Vector2 = Vector2(0, 0)) -> String:
func timestamp(fmat="{month}/{day}/{year} {24hour}:{min}:{sec}", in_utc: bool = false):
var t = OS.get_datetime(in_utc)
var hour12 = t.hour
var ampm = "AM"
if hour12 > 12:
hour12 -= 12
ampm = "PM"
var ampm = "" # Fill it in only if 12hour is requested
if "12hour" in fmat: # Only use if 12hour is visible in formating
ampm = "AM"
if hour12 > 12:
hour12 -= 12
ampm = "PM"
var result = fmat.format({"month": str(t.month).pad_zeros(2), "day": str(t.day).pad_zeros(2), "year": str(t.year).pad_zeros(4), "24hour": str(t.hour).pad_zeros(2), "12hour": str(hour12).pad_zeros(2), "min": str(t.minute).pad_zeros(2), "sec": str(t.second).pad_zeros(2), "ampm": str(ampm)})
return result