Page 1 of 1

How to Dispaly Or Echo the Apache Server Time?

Posted: Sun Dec 12, 2010 10:10 pm
by jagannathg
Hello All,

I am finding difficulties in displaying the Apache Web Server Time on my php page.

Note: I dont want to display the Local Time of the machine but I want to display the Server Time.

Can any one help me with this.

Thanks
Jagannath

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Sun Dec 12, 2010 10:26 pm
by jagannathg
Hello All,

I did some search and found, Timestamp of the start of the request is available in $_SERVER['REQUEST_TIME'].

Anyone who can help me with the useage of $_SERVER['REQUEST_TIME'] that would be great!!!

And I have a question, is it the right variable that will capture and show the Server Time?

Regards,
Jagannath

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Mon Dec 13, 2010 3:04 am
by jagannathg
Any help on this will be great!!!

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Mon Dec 13, 2010 2:05 pm
by AbraCadaver
What's wrong with:

Code: Select all

echo date('h:i:s A');
or similar format???

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Mon Dec 13, 2010 2:08 pm
by s.dot
php function time() will give you the same thing as $_SERVER['REQUEST_TIME']

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Tue Dec 14, 2010 12:28 am
by jagannathg
AbraCadaver wrote:What's wrong with:

Code: Select all

echo date('h:i:s A');
or similar format???
Thanks Shwan I got the hang of the date and time. I did some google and got some hang of the Date and Time outputs and there format. Below is my same php code for date and time formats AND Date and Time in Unix:

Date and Time Format:

Code: Select all

<html>
<head>
<title>Date and Time: Unix</title>
</head>
<body>

<?php

            //Formating the Date and Time
            //Usage of $timestamp, time() function and strftime() function
            $timestamp = time();
            echo strftime("The date today is %m/%d/%y", $timestamp);
            
            //Displaying MySQL Date Time format
            echo "<hr />";
            $dt = time();
            $dt1 = time();
            $dt2 = time();
            $mysql_datetime = strftime("%Y-%m-%d %H:%M:%S", $dt);
            $mysql_datetime1 = strftime("%d %B %Y", $dt1);
            $mysql_datetime2 = strftime("%H:%M %p", $dt2);
            echo $mysql_datetime;
            echo "<br />";
            echo $mysql_datetime1;
            echo "<br />";
            echo $mysql_datetime2;
?>

</body>
</html>
Date and Time Unix:

Code: Select all

<html>
<head>
<title>Date and Time: Unix</title>
</head>
<body>
<?php

   echo time();
   echo "<br />";
   echo mktime(10, 25, 30, 4, 13, 2011);
   echo "<br />";
   //Usage of Check Date Function

   //This will return the value as true as the Date is Valid
   echo checkdate(12,31,2010) ? 'true' : 'false';
   echo "<br />";

   //This will return the value as false as the Date is Invalid and does not exist
   echo checkdate(2,31,2010) ? 'true' : 'false';
   echo "<br />";

   //Usage of strtotime() function with now
   $unix_timestamp = strtotime("now");
   echo $unix_timestamp . "<br />";

   //Usage of strtotime() function with a specific date
   $unix_timestamp = strtotime("December 12, 2010");
   echo $unix_timestamp . "<br />";

   //Usage of strtotime() function with a future date or day
   $unix_timestamp = strtotime("+1 day");
   echo $unix_timestamp . "<br />";

   //Usage of strtotime() function with past day
   $unix_timestamp = strtotime("last Monday");
   echo $unix_timestamp . "<br />";

?>
</body>
</html>
Thanks again for your reply.

Regards,
Jagannath

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Tue Dec 14, 2010 12:33 am
by jagannathg
s.dot wrote:php function time() will give you the same thing as $_SERVER['REQUEST_TIME']
Hello s.dot,

Is there any major difference between time() function and using Global Variable $_SERVER['REQUEST_TIME']

do let me know if they are any differences and that could make some impact on the code!!!

Thanks for your reply!!!

Regards,
Jagannath

Re: How to Dispaly Or Echo the Apache Server Time?

Posted: Tue Dec 14, 2010 9:51 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
In other words, be patient. Don't post the question then bump it again 5 hours later.