Question About ISO 8601 Date

Hello, In the last few days I have been building a new project by importing data external to roblox.

However, I find myself importing date parameters in the ISO 8601, And I don’t know how to convert them to a date readable in LUA
LIke: Year: 2022 Month: 03 Day: 02 Hour: 00 Minute: 30

Did anyone know how to do that?

Thank you.

1 Like

use string.split(date," ")

local Split = string.split("Year: 2022 Month: 03 Day: 02 Hour: 00 Minute: 30"," ")
local Date = {
	["Year"] = Split[2],
	["Month"] = Split[4],
	["Day"] = Split[6],
	["Hour"] = Split[8],
	["Minute"] = Split[10],
}
print(Date)

No You Didn’t get it i need to convert an ISO 8601 Date to a Normal Date

LIke: Year: 2022 Month: 03 Day: 02 Hour: 00 Minute: 30

was Only an example.

You should use the DateTime object. It has a fromIsoDate constructor that you can use like this:

local myDate = DateTime.fromIsoDate("2022-03-02T18:47:04+00:00")

You can then turn that into a formatted string with the FormatLocalTime and FormatUniversalTime functions:

print("Parsed date: " .. myDate:FormatLocalTime("LL", "en-us"))

You can also access the individual fields, like Year, Month, and Day, with the ToLocalTime or ToUniversalTime functions, which returns a table.

1 Like

i was using the string as an example, just put the date string into the first parameter as a variable and it’ll work most likely
Edit: It seems i’m stupid, sorry lol.