user3495256
user3495256

Reputation: 153

PHP Timezone incorrect When using time()

I am using time() to record the current time in my PHP application.

I am based in the UK so we use UTC timezone. This means that in the summer/winter we switch from GMT timezone to BST (which is GMT +1). The problem was that, time() still uses GMT timezone which means it is 1 hour behind. How do I make it so it shows the BST time which is 1 hour ahead of GMT?

When I echo out the time, it is 1 hour behind.

What I have Tried:

Thanks

Upvotes: 2

Views: 661

Answers (2)

Abdulla Nilam
Abdulla Nilam

Reputation: 38609

use gmdate ()

string gmdate ( string $format [, int $timestamp = time() ] )

php.net and Different results for date() and gmdate()

Upvotes: 0

user3495256
user3495256

Reputation: 153

Found my solution.

The problem is not with time() as that is just seconds past the date.

When coming to show the date, instead of using gmdate() instead use date().

This will take into account any default timezones you set in your document/ini file.

Upvotes: 1

Related Questions