SDD
SDD

Reputation: 53

The Server Date Not Match With My Country Date

The server date/time not match with my country date/time eg server time: 11.30pm ..but my localtime already 5.3am

Upvotes: 0

Views: 808

Answers (2)

phihag
phihag

Reputation: 288100

This is likely because server and client are in different timezones.

Always use the "0 timezone" UTC to get equal time representations across the globe. In php, you can get dates in UTC by using the functions prefixed with gm, such as gmtime. Alternatively, you can set the timezone in your code with default_timezone_set:

For example, my local time in Germany is CEST or UTC+2, i.e. 2 hours before UTC:

<?php
echo 'Local time (Germany, CEST): ' . strftime('%F %H:%M:%S %z (%Z)') . "\n";
echo 'UTC (England, GMT): '       . gmstrftime('%F %H:%M:%S %z (%Z)') . "\n";
date_default_timezone_set('America/Los_Angeles');
echo 'LA time (US, PDT): '          . strftime('%F %H:%M:%S %z (%Z)') . "\n";

This outputs:

Local time (Germany, CEST): 2011-07-08 14:24:56 +0200 (CEST)
UTC (England, GMT):         2011-07-08 12:24:56 +0000 (GMT)
LA time (US, PDT):          2011-07-08 05:24:56 -0700 (PDT)

Upvotes: 1

Mor&#242;Switie
Mor&#242;Switie

Reputation: 1516

If you want your script to match your localtime change your php timezone. if you use apache you can use a .htaccess file.

Or just put this before your php code

<?php

date_default_timezone_set( 'Europe/Amsterdam' );

//the rest of your code

?>

replace 'Europe/Amsterdam' with your own timezone. have a look at: http://php.net/manual/en/timezones.php for a list of timezones

Upvotes: 0

Related Questions