![]() |
Class for getting serverside date and time
Edit: I made an error in the formal month function. This has been updated. I also needed to swap two lines in the date function. Updated as well.
New Edit: I stated that the getDate function could be made better. It was using a while loop to go though each year. I redid the math so it handled all the leap year rules linerally (leap years dont occur on years evenly divisible by 100 but not divisible by 400, so although 1900 is divisble by 4, its not a leap year.) Now instead of running through the loops x amount of years since 1970, it only runs through the loop 4 times, which is far far far more efficient, for even 5000 years. You can see the old getDate function at the bottom of this post. NEWER Edit: Added getUTC, a function that will get the number of seconds since Jan. 1st, 1970, when given the year, month, day, hour, minutes, and seconds. At the bottom of this post, in green, I will show a demo of how to use it to find out what day of the week any given date will be. ------------------------------------------------------------------ Someone posted a thread about this, so I made a class for the world to enjoy for various functions for serverside date and time. I just wrote this up quickly to help out. Note from Skyld: Hell Raven requested I update the getUTC() function; this post and the code snippet below has been updated to reflect those changes. [1] PHP Code:
PHP Code:
Classic (Server): Saturday, February 17th, 2007 @ 8:34:53 PM EST The following is a demo using getUTC to find out what day of the week any given day will be. In my case, I made a poorly coded demo to tell what day 4/17/2009 will be. This is just to show a way that getUTC can be useful. PHP Code:
Classic (Server): 4/17/2009 will be a Friday Edit Subnote: This is the old getDate function that was replaced. I leave this here so you can see an example of an infinite structure vs a finite one. You should always try to make a structure finite if possible. This repeats for as many years as it needs to, the newer function above only needs exactly 4 loops. Learn from this ^-^ PHP Code:
|
Impressive, reputation increase!
|
Does what it should do, but not too impressive.
|
Quote:
|
I am bumbing this because I made an error in the getUTC, that caused an addition/subtraction of a day in the getUTC function.
The code needs to be replaced with: PHP Code:
|
This is very nice, thanks for making it! Modded it slightly for my server (clientside time). Hope you dont mind ^^
If you do, just tell me, I'll remove it. |
Quote:
|
*necromancy*
I think this should be stickied, could someone do that? Also Graal's timevar2 seems to be out of synch after I just synched my clock to the time server. So I added this function to make match the clock on my computer by the second. PHP Code:
|
wait for timevar3?
|
Quote:
If this is clientside and on Windows, then timevar2 isn't doing what you think. (Windows version's clientside timevar2 is using the amount of seconds after the client has been opened, Linux/Mac and serverside use timevar2 as true UNIX time.) Quote:
|
Everything I did was on serverside (Val Dev), so I am indeed saying that the gserver time needs updating.
|
would their be a way to make this show up in the corner of your client? because my friend shakaraja is trying to make one..
|
The client would have to be synched to the server
|
Why not just add screenshot functionality for scripts, have it detect what type of computer, take a screenshot snippet of the correct place, use an online PHP OCR system that returns the correct time, then use that! Much simpler, fools.
|
| All times are GMT +2. The time now is 12:43 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.