compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 30 Jan 2015 08:23 AM |
I have once seen a place (Checkpoint Racing) where we could rent a garage for an amount of in-game coins, this allowed us to save a vehicle. When you bought it you received a date, when you didn't extend your rent before the day your car was lost.
How do I get the date and time inside of a script? |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2015 08:35 AM |
| http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#os.time |
|
|
| Report Abuse |
|
|
compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 30 Jan 2015 08:40 AM |
timetable = {0,0,0,0,0,0,false} os.time(timetable) print(table.concat(timetable,", "))
Output: ServerScriptService.Script:2: field 'day' missing in date table |
|
|
| Report Abuse |
|
|
compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 30 Jan 2015 08:51 AM |
I found how to do it using tick() With that I can easily make a function that calculates the years, months, days, hours, seconds since January 1st, 1970 making me able to find out what date/time it is now. |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 30 Jan 2015 08:52 AM |
| Listen, if you make a date system with tick(), you will have a date system based on the computer time. If you do os.time, you will have the same as tick() but with the UTC time, not computer time. k |
|
|
| Report Abuse |
|
|
compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 30 Jan 2015 09:06 AM |
Ok thanks.
But then with os.time there appears to be a way to put it in a table, how can I do that because it doesn't appear to work for me... |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 30 Jan 2015 09:29 AM |
I don't know how the os.time parameters work, because whatever, but you know you can like, always get differences and stuff.
preview. c9. io/lunate/skyewashere/Time.lua
Contains most of the important math for collecting and/or formatting time. |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2015 09:45 AM |
I also made a ModuleScript showing the different ways of doing it: http://www.roblox.com/RealTimeModule-item?id=188363586
--ModuleMaker |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 30 Jan 2015 10:03 AM |
| You could also use a webserver and retrieve the clock from there and skip all the math. |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2015 11:14 AM |
@compy in your tick() script, just replace tick() with os.time()
Don't forget to take in leap years! |
|
|
| Report Abuse |
|
|
compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 01 Feb 2015 09:50 AM |
I made myself a clock as a test and it works fine:
local TimeZone = -5 while true do local A = math.fmod(os.time(),86400) local B = math.floor(A/3600) + 5 + TimeZone local H = B local M = math.floor(A/60 - 60*B) local S = math.floor(math.fmod(A,60)) if string.len(H) == 1 then H = "0" .. H end if string.len(M) == 1 then M = "0" .. M end if string.len(S) == 1 then S = "0" .. S end script.Parent.Time.Text = H .. ":" .. M .. ":" .. S wait(1) end |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|