How to set PHP 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
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

How to set PHP time?

Post by intellivision »

My server's time is dead on (Cent OS via Plesk). But when I do a

Code: Select all

<?php echo(date('m-d-Y h:s',time())); ?>
I get a time that's about 24 minutes in the future. :?

Any ideas?
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Re: How to set PHP time?

Post by intellivision »

Whoa... I just ran that code again four times in one minute and got the following:

11-19-2008 04:01
11-19-2008 04:45
11-19-2008 04:59
11-19-2008 04:25

So strike the bit about 24 minutes. My PHP time is drunk.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: How to set PHP time?

Post by andyhoneycutt »

Your date formatting is off, try:

Code: Select all

 
// Wrong (month, day, year, hours, seconds:
echo(date('m-d-Y [color=#FF0000]h:s[/color]',time()));
// Right: (month, day, year, hours, minutes:
echo(date('m-d-Y [color=#00BF00]h:i[/color]',time()));
-Andy
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Re: How to set PHP time?

Post by intellivision »

Andy, thanks!

I think I was randomizing or something. Oy vey. Gracias.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: How to set PHP time?

Post by andyhoneycutt »

No problem, next time instead of blaming your php for being drunk, you might want to take a breathalyzer youself :)
Post Reply