pyxfluff
(Pyx)
January 20, 2023, 11:41pm
#1
Hello,
I was working on adding timed bans, when I ran into a wall. I cant exactly get the account age of somebody out of the game.
I went looking in the API and found the https://users.roblox.com/v1/users/*
endpoint, but that returns a date, which doesn’t really help me.
"created": "2016-06-08T21:50:52.52Z",
I’m just looking for a simple number on how many days since their account creation. Thank you!
KJry_s
(MalleoZephyris)
January 20, 2023, 11:52pm
#2
Someone already made a post like this:
Hey! I am currently trying to display an account join date, but without the time. Here is what the raw date and time looks like: 2012-06-17T13:52:09.243Z
I was wondering if it was possible to get specific information from the string like the year, the month and the day alone. If anyone knows how I could format it, I would appreciate it. I was also wondering if it was possible to get the number of days since an account joined too.
local example = "2012-06-17T13:52:09.243Z"
local day, time = string.match(example, "(%d+%-%d+%-%d+)T(%d+:%d+:%d+%.%d+)Z")
Another post on github :
function parse_json_date(json_date)
local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%+%-])(%d?%d?)%:?(%d?%d?)"
local year, month, day, hour, minute,
seconds, offsetsign, offsethour, offsetmin = json_date:match(pattern)
local timestamp = os.time{year = year, month = month,
day = day, hour = hour, min = minute, sec = seconds}
local offset = 0
if offsetsign ~= 'Z' then
offset = tonumber(offsethour) * 60 + tonumber(offsetmin)
if xoffset == "-" then offset = offset * -1 end
end
return timestamp + offset
end
print(string.format('%d', parse_json_date('2017-05-25T06:21:43Z')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43+0830')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43-0400')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43.213Z')))
1 Like
You could also just use the DateTime
library. The method the OP would want is DateTime.fromIsoDate
:
-- Example
local dateData = DateTime.fromIsoDate("2016-06-08T21:50:52.52Z"):ToLocalTime()
print(dateData.Year) -- Prints 2016
pyxfluff
(Pyx)
January 21, 2023, 1:21am
#4
Hey, the code is returning a date string, when I was trying to make it a plain number (such as 123)