I’m wondering if it’s possible to escape using dateTime:FormatLocal/UniversalTime?
I’m currently trying to make a string with a prefix of ‘Recording’, and then some info about when the recording took place, however I’m having trouble doing so since the ‘d’ gets recognized as the elemental token ‘d’.
local s = now:FormatLocalTime('Recording-MMM-DD-YYYY_hh:mm:ss.SSSSA', 'en-us')
print(s) --> Recor3ing-Jun-07-2023_12:18:30.5975AM
I’ve tried using generic string library escapes (\ and %) to no avail.
local s = now:FormatLocalTime('Recor%ding-MMM-DD-YYYY_hh:mm:ss.SSSSA', 'en-us')
print(s) --> Recor%3ing-Jun-07-2023_12:18:30.5975AM
local s = now:FormatLocalTime('Recor\ding-MMM-DD-YYYY_hh:mm:ss.SSSSA', 'en-us')
print(s) --> Recor3ing-Jun-07-2023_12:18:30.5975AM
I’ve tried googling, checking the devhub etc but there aren’t many results, and the results that are there talk about different issues.
I know concatenation/string formatting is an option here but I want to avoid doing so if necessary. If there is not another option then so be it.
local dateArray = os.date("*t")
print(dateArray.month .. "/" .. dateArray.day .. "/" .. dateArray.year) -- Prints 6/6/2023 (Well for me, it might be different for you)
I want to avoid using os.date if possible as DateTime automatically localizes (actually os lib might but not 100% sure), has more options, allows for more precision etc.
So you know, you also don’t need to concatenate like this (and I’d advise against it as it’s slow since it reconstructs the string for every concatenation operator).
I know you’re trying to avoid concatenation, but you can use this:
local now = DateTime.now()
local s = now:FormatLocalTime('MMM-DD-YYYY_hh:mm:ss.SSSSA', 'en-us')
print('Recording-' .. s) -- Unlike earlier, ignore any d's in a string, and prints "Recording-Jun-07-2023_12:18:30.5975AM"
I find it a bit simpler, and there aren’t really any other apparent solutions.