Sign in to follow this  

[web] Trying to display the current time in PHP

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been learning a bit of basic PHP, and I've hit a snag (again). I've got some code to display the current time, but it isn't working correctly. Here's my index.php code:
<?php
include "includes/time.inc.php";
$timeOutput = new time;
?>

<font color=black>
<? $timeOutput->generateTime(); ?>
<? $timeOutput->displayTime(); ?>
</font>

And here's the file "time.inc.php":

<?
class time {

	var $time;

	function generateTime() {

		$time = getDate();

		foreach ($time as $key => $value) {

			print $key.": ".$value."<BR>";

		}

	}

	function displayTime() {

		print ($time['weekday'].", ".$time['mday']." ".$time['month']." ".$time['year']);

	}

}
?>

But here's what gets output:
seconds: 34
minutes: 15
hours: 21
mday: 18
wday: 0
mon: 12
year: 2005
yday: 351
weekday: Sunday
month: December
0: 1134940534
,
Where the comma is, you can see from the code it should say something like "Sunday, 18 December 2005" - but it doesn't, I just see the comma. The time is obviously being generated fine as it's being printed out by the generateTime() method. So where am I going wrong? Does PHP treat variables in a different way, or something? Thanks for your help, ukdeveloper.

Share this post


Link to post
Share on other sites

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this