How to Dispaly Or Echo the Apache Server Time?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jagannathg
Forum Commoner
Posts: 34
Joined: Wed Dec 08, 2010 1:55 am

How to Dispaly Or Echo the Apache Server Time?

Post 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
jagannathg
Forum Commoner
Posts: 34
Joined: Wed Dec 08, 2010 1:55 am

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

Post 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
jagannathg
Forum Commoner
Posts: 34
Joined: Wed Dec 08, 2010 1:55 am

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

Post by jagannathg »

Any help on this will be great!!!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post by AbraCadaver »

What's wrong with:

Code: Select all

echo date('h:i:s A');
or similar format???
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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

Post by s.dot »

php function time() will give you the same thing as $_SERVER['REQUEST_TIME']
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
jagannathg
Forum Commoner
Posts: 34
Joined: Wed Dec 08, 2010 1:55 am

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

Post 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
jagannathg
Forum Commoner
Posts: 34
Joined: Wed Dec 08, 2010 1:55 am

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

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply