i got last online date with getting async “https://api.roproxy.com/users/"..Id.."/onlinestatus/”
and split them with
local _,First = string.find(PlayerInfo, ',"LastOnline":"')
local Last,_ = string.find(PlayerInfo, '","LocationType":')
local LastOnline = string.sub(PlayerInfo, First, Last)
so, i got “2022-07-17T09:22:03.5-05:00”
i want to make friendlist showing “Online 5 hours ago!” things.
so, i have the make the value to numbere like DateTime.now()
is there any easy way?
You’re looking for HttpService:JSONDecode, this takes the content provided by the url, and turns it into a Lua table
-- Example
local fetch = HttpService:GetAsync("https://api.roproxy.com/users/1/onlinestatus") -- Get the web content
local luaTable = HttpService:JSONDecode(fetch) -- Decode the JSON table into a Lua table
print(luaTable.LastOnline)
No. i already got Detail without JSONDecode.
i need to make the detail to os style.
just understand I looking for How long has it been since
Of course, since this time changes frequently, an formula to calculate it is required.
Just use DateTime.fromIsoDate
:
local d = "2022-07-17T09:22:03.5-05:00"
local s = DateTime.fromIsoDate(d)
print(s, os.date("%c", s.UnixTimestamp)) -- prints the number of seconds since the unix epoch from the specified date and the date formatted
-- This makes it easier since your working with the seconds now
From there, just use the system you have to display when they were last online
2 Likes
The DateTime
class includes a fromIsoDate
that will construct a DateTime
object from a string formatted like that.
Then you can find the difference between then and now in seconds.
local lastLoginDateStr = "2022-07-17T09:22:03.5-05:00"
local lastLoginDate = DateTime.fromIsoDate(lastLoginDateStr)
local nowDate = DateTime.now()
local secondsPassed = nowDate.UnixTimestamp - lastLoginDate.UnixTimestamp
print("Last login was " .. secondsPassed .. " seconds ago")
1 Like