Sendy Posted March 12, 2019 Share Posted March 12, 2019 Hello, i need help with timestamp how to get time remaining from timestamp? example: timestamp = 1552450302 Remaining: 02:05:20 - 05:02:14 please help anyone Link to comment
Investor Posted March 12, 2019 Share Posted March 12, 2019 If you're asking for time remaining until a specific target timestamp, then local target = --[[ some timestamp ]] local current = getRealTime().timestamp local remaining_time = target - current local hours = math.floor((remaining_time % 86400) / 3600) local mins = math.floor((remaining_time % 3600) / 60) local secs = math.floor(remaining_time % 60) 1 Link to comment
XaskeL Posted March 12, 2019 Share Posted March 12, 2019 local target = os.time() + 86399 local current = os.time() local remaining_time = target - current local hours = math.floor((remaining_time % 86400) / 3600) local mins = math.floor((remaining_time % 3600) / 60) local secs = math.floor(remaining_time % 60) local msg = string.format("%02d:%02d:%02d", hours, mins, secs) You can also format the code from the solution above using this method with string.format. result: 23:59:59 1 Link to comment
Sendy Posted March 12, 2019 Author Share Posted March 12, 2019 (edited) Thanks when i want add years, months, days? local years = math.floor((remaining_time % number) / number) local months = math.floor((remaining_time % number) / number) local days = math.floor((remaining_time % number) / number) local hours = math.floor((remaining_time % 86400) / 3600) local mins = math.floor((remaining_time % 3600) / 60) local secs = math.floor(remaining_time % 60) Edited March 12, 2019 by Sendy Link to comment
Investor Posted March 12, 2019 Share Posted March 12, 2019 (edited) Months have variable length so I wouldn't advise using that. If you need to, use the average month length which is actually slightly >30 days, meaning 2592000 seconds (more more accurately, 30.44 days = 2630016 seconds) in a month. local years = math.floor(remaining_time / 31557600) local months = math.floor((remaining_time % 31557600) / 2592000) local days = math.floor((remaining_time % 2592000) / 86400) local hours = math.floor((remaining_time % 86400) / 3600) local mins = math.floor((remaining_time % 3600) / 60) local secs = math.floor(remaining_time % 60) Edited March 12, 2019 by Investor 1 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