Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Functions to get the current time (https://forums.graalonline.com/forums/showthread.php?t=80916)

Crow 07-28-2008 10:13 PM

Functions to get the current time
 
I've written some functions to return the current time of the day, even in seconds. Seconds isn't that accurate because I'm using timevar, but it should do. The functions using timevar also means you can use this both clientside and serverside, which comes in pretty handy sometimes.
The only problem is that it is off when your servertime is off, and the timezone is also the one the server is in/the servertime is set to. You can adjust this by yourself though, shouldn't be a huge problem.
I hope you can find some use for this!

PHP Code:

//time functions
function getDayTime() {
  
//timevar * 5, it incs by 1 every 5 secs; - 30 secs; - 26 mins; - 4 hours
  
temp.fixedTimeVar = ((timevar 5)        - 30       60 26  60 60 4);
  return 
fixedTimeVar # 86400;
}

public function 
getTimeHours() {
  
temp.var = intgetDayTime() / 3600 );
  return (
temp.var < 10 "0" temp.var : temp.var);
}
public function 
getTimeMinutes() {
  
temp.var = int( (getDayTime() # 3600) / 60 );
  
return (temp.var < 10 "0" temp.var : temp.var);
}
public function 
getTimeSeconds() {
  
temp.var = intgetDayTime() # 60 );
  
return (temp.var < 10 "0" temp.var : temp.var);


Note: Replace the # with %, the html code for it won't work in [php] tags.


Edit: Changed some code, less lines now, and I changed something that didn't really make sense after all, I have no idea why I divided by 10 in the first place...oh yea, and I forgot to mention, if the hours/minutes/seconds are smaller than 10 (so basically only one digit), it adds a 0 infront of it.

cbk1994 07-28-2008 10:14 PM

http://forums.graalonline.com/forums...ad.php?t=72260

Good job, but it's already been done.

Crow 07-28-2008 10:19 PM

Ah, dangit, I didn't see that. Seems a bit complicated though, maybe if people want something simple? :p

cbk1994 07-28-2008 10:25 PM

Quote:

Originally Posted by Crow (Post 1409395)
Ah, dangit, I didn't see that. Seems a bit complicated though, maybe if people want something simple? :p

Yours doesn't get the date though, which can be very important in some cases (e.g. logging stuff).

Crow 07-29-2008 12:11 AM

My functions aren't made for logging purposes ;f

Tigairius 07-29-2008 03:42 AM

Neat, great job :D

TheStan 07-29-2008 03:52 AM

Good Job Crow.

Chompy 07-29-2008 12:43 PM

Me like simpleness :]

And Chris, Kristi's is more advanced and is serverside..
Crow's simple and works on both sides =]


All times are GMT +2. The time now is 07:42 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.