Spoiler
This can probably be done neater but />
Its not like you have one.. Right?
Oh and the reason this is bigger then it needs to, I couldn't find a time server I could access and set custom offset hours to.
So I ended up making my own offset thingy.
However as this is fetching from the internet, There will be a lag until it fetches the data or dies trying.
Returns it in a table.
19:13:33
Tuesday
24
April
2012
24/4/2012
So you can use Time,Day,DayNo, Month,Year,FormattedDate = time(0)
print(Time)
print(Day)
print(DayNo)
print(Month)
print(Year)
print(FormattedDate)
or
for _,n in pairs(time(0)) do
print(n)
end
Spoiler
function time(offset) -- Get the time, offset to set the time off by bla bla hours if not offset then error("Please enter a number to offset the time by. Use 0 if you dont want to offset it") end local Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"} local Months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} local DaysInMonths = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} local res = http.get("http://nist.time.gov/timezone.cgi?UTC/s/0/") local Res = {} local DateFormat = "" local bla = "" local Date = "" local Time = "" local BlaDate = "" local BlaTime = "" local BlaDays = "" local BlaMonth = "" if res then while true do bla = res.readLine() if bla then Res[#Res+1] = bla else break end end res.close() Time = string.sub(Res[49], 63, string.len(Res[49])-4) Date = string.sub(Res[50], 53, string.len(Res[50])-4) DateFormat = {Time} for n=1,3 do if string.find(Date, ", ") then local s,len = string.find(Date, "%, ") DateFormat[#DateFormat+1] = string.gsub(string.sub(Date, 1, s), "%,", "") Date = string.sub(Date, len+1, string.len(Date)) end end DateFormat[#DateFormat+1] = Date if string.sub(DateFormat[3], string.len(DateFormat[3])-2, string.len(DateFormat[3])-2) == " " then BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3])-1, string.len(DateFormat[3]))) else BlaDate = tonumber(string.sub(DateFormat[3], string.len(DateFormat[3]), string.len(DateFormat[3]))) end DateFormat[3] = string.gsub(DateFormat[3], BlaDate, "") BlaTime = tonumber(string.sub(DateFormat[1], 1, 2))+tonumber(offset) repeat if BlaTime > 24 then BlaDate = BlaDate+1 BlaTime = BlaTime-24 elseif BlaTime < 0 then BlaDate = BlaDate-1 BlaTime = BlaTime+24 end until BlaTime > 0 and BlaTime < 24 if string.len(BlaTime) == 1 then BlaTime = "0"..BlaTime end end DateFormat[4] = tonumber(DateFormat[4]) BlaMonth = string.gsub(DateFormat[3], " ", "") TheDays = BlaDate o = 1 repeat if Months[o] == BlaMonth then BlaDate = TheDays+BlaDate else BlaDate = BlaDate+DaysInMonths[o] end o = o+1 until Months[o] == BlaMonth repeat if BlaDate > 365 then BlaDate = BlaDate-365 DateFormat[4] = DateFormat[4]+1 end until BlaDate < 366 local o = 1 local TempNo = BlaDate repeat -- Turn this into a 7 day TempNo = TempNo-7 until TempNo < 8 DateFormat[2] = Days[TempNo] repeat -- Get it into a format for the proper month BlaDate = BlaDate-DaysInMonths[o] o = o+1 until BlaDate <= DaysInMonths[o] BlaMonth = Months[o] DateFormat[3] = BlaMonth DateFormat[1] = BlaTime..string.sub(DateFormat[1], 3, string.len(DateFormat[1])) DateFormat[5] = BlaDate.."/"..o.."/"..DateFormat[4] table.insert(DateFormat, 3, BlaDate) return unpack(DateFormat) end
This can probably be done neater but />
Its not like you have one.. Right?
Oh and the reason this is bigger then it needs to, I couldn't find a time server I could access and set custom offset hours to.
So I ended up making my own offset thingy.
However as this is fetching from the internet, There will be a lag until it fetches the data or dies trying.
Returns it in a table.
19:13:33
Tuesday
24
April
2012
24/4/2012
So you can use Time,Day,DayNo, Month,Year,FormattedDate = time(0)
print(Time)
print(Day)
print(DayNo)
print(Month)
print(Year)
print(FormattedDate)
or
for _,n in pairs(time(0)) do
print(n)
end