drifterCZE Posted May 12, 2011 Share Posted May 12, 2011 Hello... I am looking for an func which gives me actual unix time... but I can't find any... os.time() doesnt work and MTA function getRealTime() is able to return timestamp only in MTA 1.1+ Is there any other way than getting {second, minute, day, month, year} from getRealTime() and calculate it by me own? Thanks Link to comment
Castillo Posted May 12, 2011 Share Posted May 12, 2011 Do you mean this? local realTime = getRealTime() date = string.format("%04d/%02d/%02d", realTime.year + 1900, realTime.month + 1, realTime.monthday ) time = string.format("%02d:%02d", realTime.hour, realTime.minute ) Link to comment
drifterCZE Posted May 12, 2011 Author Share Posted May 12, 2011 No. I want to get something like "1305239697" Link to comment
Castillo Posted May 12, 2011 Share Posted May 12, 2011 I think here's what you looking for: https://wiki.multitheftauto.com/wiki/Useful_Functions The script: function isLeapYear(year) if year then year = math.floor(year) else year = getRealTime().year + 1900 end return ((year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0) end function getTimestamp(year, month, day, hour, minute, second) -- initiate variables local monthseconds = { 2678400, 2419200, 2678400, 2592000, 2678400, 2592000, 2678400, 2678400, 2592000, 2678400, 2592000, 2678400 } local timestamp = 0 local datetime = getRealTime() year, month, day = year or datetime.year + 1900, month or datetime.month + 1, day or datetime.monthday hour, minute, second = hour or datetime.hour, minute or datetime.minute, second or datetime.second -- calculate timestamp for i=1970, year-1 do timestamp = timestamp + (isLeapYear(i) and 31622400 or 31536000) end for i=1, month-1 do timestamp = timestamp + ((isLeapYear(year) and i == 2) and 2505600 or monthseconds[i]) end timestamp = timestamp + 86400 * (day - 1) + 3600 * hour + 60 * minute + second timestamp = timestamp - 3600 --GMT+1 compensation if datetime.isdst then timestamp = timestamp - 3600 end return timestamp end For me it returned: 1305222073 Link to comment
drifterCZE Posted May 12, 2011 Author Share Posted May 12, 2011 Hm, thanks... But I think there must be something "easier" anyway... because thoose things u use to get Unix time are originaly calculated from Unix time, it must got it from some alternative func to os.time... Link to comment
Castillo Posted May 12, 2011 Share Posted May 12, 2011 Well, that's what i found, let's see if someone else know something else. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now