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 » Scripting Helpers
Home Search
 

Re: Get hours from Unix timestamp (tick())

Previous Thread :: Next Thread 
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 02:52 PM
I can't figure it out. I have the rest of the algorithm (below) but hours aren't working right.

local secondsPassed = os ~= nil and os.time() or tick()
local year = 1970 + math.floor(secondsPassed / (86400 * 365.25))
local days = math.floor((secondsPassed % (365.25 * 86400)) / 86400)
days = days + (year - 2011)
-- BROKEN
-- 86400 = 1 day (60*60*24)
local hours = math.floor((secondsPassed % 86400) / 3600)

local minutes = math.floor((secondsPassed % 3600) / 60)
local seconds = math.floor(secondsPassed % 60)
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:01 PM
days_now = math.floor(tick() / (60 * 60 * 24))
years_now = math.floor(days_now / 365.25)
months_now = years_now * 12
hours_now = days_now * 24
minutes_now = hours_now / 60
seconds_now = math.floor(tick())

Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:05 PM
That doesn't work

print(hours_now) --> 376680
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:06 PM
Yes, that prints the hours since January 1st 1970...

- thedestroyer115
Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:07 PM
Not the current hour, though. How would i get that?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:09 PM
You wanted the current hour?
Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:10 PM
Yes.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:11 PM
print(hour_now / days_now)

Maybe?
Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:12 PM
Nope. Sorry.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:23 PM
hours_now = math.floor(tick() / (60 * 60))
days_now = math.ceil(tick() / (60 * 60 * 24))
d = days_now * 24
print(d - hours_now)


Here you go.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
21 Dec 2012 03:23 PM
Returns the time in UNIX time, which is the number of seconds since the Unix epoch, January 1st, 1970. This time advances without game running, network synchronization, or wait(). Using tick() in a LocalScript may result in a different number that if you were to use it in a Script because using it in a LocalScript will fetch the user's current time while using it in a Script will fetch the server's current time. tick() is very accurate. Because of its high accuracy, it can be used to measure the time a certain function takes to execute by calling it before and after an operation has been done, then finding the difference.

Using tick() in a LocalScript may result in a different number that if you were to use it in a Script because using it in a LocalScript will fetch the user's current time while using it in a Script will fetch the server's current time.

LocalScript will fetch the user's current time
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:24 PM
Or do some maths like I did.

- thedestroyer115
Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:43 PM
Destroyer:
That still doesn't work. The output is '3' when it should be '12'
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
21 Dec 2012 03:45 PM
Different time zones man.

- thedestroyer115
Report Abuse
mlnlover11 is not online. mlnlover11
Joined: 20 Jan 2009
Total Posts: 47
21 Dec 2012 03:47 PM
How is that time-zone dependant? I'm using os.time instead of tick so it should be local time, which shouldn't need time zones.
Report Abuse
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
21 Dec 2012 03:59 PM
If you want to get the player's local time, place tick() in a LocalScript, then place it in the player, the player's character, tool, gui, something player-oriented
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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