generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Getting date/time

Previous Thread :: Next Thread 
compy111 is not online. 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
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
30 Jan 2015 08:35 AM
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#os.time
Report Abuse
compy111 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
ModuleMaker is not online. ModuleMaker
Joined: 26 Sep 2014
Total Posts: 182
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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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 is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
01 Feb 2015 10:11 AM
Eww
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image