Find the true time

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Find the true time

Post by phice »

Code: Select all

// Finding the true time
	function ttime()
	{
		// Caclulate
		$time  = (date("Y") * 31556926);	// + [Number of Years]   X [Seconds in a Year]
		$time += (date("z") * 86400);		// + [Number of Days]    X [Seconds in a Day]
		$time += (date("G") * 3600);		// + [Number of Hours]    X [Seconds in a Hour]
		$time += (date("i") * 60);		// + [Number of Minutes] X [Seconds in a Minute]
		$time += date("s");			// + [Number of Seconds]
		
		// Return
		return $time;
	}
Use this function to show the actual seconds from year 0.
Image Image
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Does a Year always have 31556926 seconds?

Leap years?

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

31556926 = 365 days, 5 hrs, 48 min, 46 seconds.
31557600 = 365 days, 6 hrs. This accounts for leap years, but not leap seconds.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

feyd wrote:31556926 = 365 days, 5 hrs, 48 min, 46 seconds.
31557600 = 365 days, 6 hrs. This accounts for leap years, but not leap seconds.
I don't understand what you are saying there?

How does the second account for leap years? it is only about 12mins more
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

1 extra day per 4 years. 6hrs = 0.25 days.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

So, what if i used the function to get the seconds from year 0, and the last yeap year was 2 years ago.

Would the result be slightly inaccurate?

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it should be more accurate..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

but it wouldn't find "Find the true time" as stated
Post Reply