Help with converting a date

Hello, I’m currently trying to convert something like this:

“2006-08-14T01:03:01.16Z”

into something like this:

“Monday 12th of June 2024”

If you know how to do it, please help me out with this.
Any help is appreciated!

2 Likes

Have you tried using this section of os.date?

1 Like

Yes, and it didn’t really work. I don’t know if I used it correctly but I can’t get it to print the day of the week and the month.

Just figured out there’s a better version of os.date (kinda)

It seems to better fit what you want:

1 Like

I think os.time could work, but I first need to convert the raw string into a lua DateTime, which I’m not able to do.

1 Like

Is the date you showed in your topic the only one that comes up or is it completely random but in that format?

I’m getting this form a value called [“created”] when I get a user’s profile infos with HttpService:
image

1 Like

The time it was created is

playerInfo["created"]

or just

playerInfo.created

“created” is essentially the name of the actual time value there

1 Like
local dateString = "2006-08-14T01:03:01.16Z"
local isoDate = DateTime.fromIsoDate(dateString)

local formattedTime = isoDate:FormatLocalTime("LL", "en-us")

This will give you a formatted date of: August 13, 2006.

1 Like

playerInfo.created , the second option

Yep, OP this is the solution.

30char

1 Like

All of these “solutions” are well and good, but the definitive solution is this:

DateTime:fromIsoDate

local isoDate = "2006-08-14T01:03:01.16Z"
local datetime = DateTime.fromIsoDate(isoDate)
print(datetime.FormatUniversalTime("LL", "en-us"))

This is strictly from the DateTime documentation.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.