DATE & 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
kennedysee
Forum Newbie
Posts: 14
Joined: Fri Dec 04, 2009 12:17 am

DATE & TIME

Post by kennedysee »

Why the date and time is not exact with my timezone? and the data ends with a ":st"...

$time = time();
$tstamp = date("m/d/y h:i:S", $time);

01/21/10 08:28:st


Anyone help??
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: DATE & TIME

Post by requinix »

kennedysee wrote:Why the date and time is not exact with my timezone?
And what date and time does your computer/server think it is?
Windows: check the clock on the taskbar (dur)
Unix: run `date`
kennedysee wrote:and the data ends with a ":st"
Because 'S' means "English ordinal suffix for the day of the month, 2 characters".
Read the documentation
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: DATE & TIME

Post by pbs »

It will show your local machine date/time if you are testing it on local machine. And if you are checking it on live server it will show the server time. You need to mention time zone at the top of your php code in ( date_default_timezone_set(string timezone_identifier) ) function or configure it in php.ini file.
kennedysee
Forum Newbie
Posts: 14
Joined: Fri Dec 04, 2009 12:17 am

Re: DATE & TIME

Post by kennedysee »

$time = time();
$tstamp = date("m/d/y h:i:s", $time);

if let say, i want to set my timing to GMT+8... how do i do that?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: DATE & TIME

Post by pbs »

User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: DATE & TIME

Post by requinix »

pbs wrote:You can refer this for time zones http://php.net/manual/en/function.date- ... ne-set.php
Of note is the Others, which mentions formats like

Code: Select all

date_default_timezone_set("Etc/GMT-8");
echo date("m/d/y h:i:s");
But
1) The pluses and minuses are reversed from what you think they are
2) They don't account for daylight savings
So don't use them unless you know exactly what you're doing.
kennedysee
Forum Newbie
Posts: 14
Joined: Fri Dec 04, 2009 12:17 am

Re: DATE & TIME

Post by kennedysee »

tasairis wrote:
pbs wrote:You can refer this for time zones http://php.net/manual/en/function.date- ... ne-set.php
Of note is the Others, which mentions formats like

Code: Select all

date_default_timezone_set("Etc/GMT-8");
echo date("m/d/y h:i:s");
But
1) The pluses and minuses are reversed from what you think they are
2) They don't account for daylight savings
So don't use them unless you know exactly what you're doing.

THANKS ALOT :)
Post Reply