How would I go about converting ISO8601 into a time and date?

So basically I am trying to get the time my game was updated through a script. I am trying to make a SurfaceGui with a textlabel that displays “This game was last updated [month] [day], [year]”. I am not sure how to go about with doing this because I have searched the devforum and scriptinghelpers but nothing is helping. I am getting the time the game was updated using the Games API. Heres my code:

local HttpService = game:GetService("HttpService")
local TextLabel = workspace.ScreenUpdated.SurfaceGui.TextLabel
local GameUpdated = HttpService:JSONDecode(HttpService:GetAsync(" universeIds="[1].updated

TextLabel.Text = "This game was last updated "..GameUpdated

However, it always returns something like 2017-09-26T22:43:21.667Z
Any help?

For the time being, since I don’t actually know how to do this, you’ll probably be able to make something temporary out of this. First of all, we need to assume three things:

  • ISO 8601 will always be YYYY-MM-DD.
  • You only need the day, month and year. Time is irrelevant to your use case.
  • You won’t change your mind later how much information you need from ISO 8601.

In this case, you can just fetch the date format and sub it across how many characters the date occupies (including all numerals and separators, 4 + 1 + 2 + 1 + 2 = 10), then feed that into string.split with the date seperator as your delimiter (split uses a plaintext delimiter). You will then be supplied an ordered array in Y -> M -> D order.

local GameUpdatedRaw = HttpService:JSONDecode(HttpService:GetAsync(""[1].updated
local GameUpdatedDate = GameUpdatedRaw:sub(1, 10)
local GameUpdated = GameUpdatedDate:split("-")
print(table.unpack(GameUpdated)) -- 2017 09 26
print(GameUpdated[1]) -- 2017

If you needed time using this method, it would be a matter of increasing the steps by getting the parts after the T and then splitting by a colon. At that point though, this method falls through and it would be better to look into other methods - even as far as just making assumptions with a string pattern. Don’t quite know how you’d go about that though.

1 Like

I found a script here that may be helpful. It looks like it takes the full ISO8601 timestamp and converts it into Unix time (seconds since 1/1/1970). This is the same format that os.time() returns. From here, you can use to format it.