Get Standard Time in South Africa at Php

this function is used to get the current time of my system, I want to get the time in South Africa, so plz will direct me.

$today = time () ; 
+6
php
source share
3 answers

For example:

 <?php date_default_timezone_set('Africa/Johannesburg'); echo date('Ymd H:i:s', time()); 
+12
source share
 $d = new DateTime("now", new DateTimeZone("Africa/Johannesburg")); echo $d->format("r"); 

gives

  Mon, 07 Jun 2010 02:02:12 +0200

You can change the format. See http://www.php.net/manual/en/function.date.php

time() gives the number of seconds since January 1, 1970 00:00:00 GMT (excluding seconds of a jump), so it does not depend on the time zone.

EDIT: for the countdown you can:

 $tz = new DateTimeZone("Africa/Johannesburg"); $now = new DateTime("now", $tz); $start = new DateTime("2010-06-11 16:00:00", $tz); $diff = $start->diff($now); echo "Days: " . $diff->format("%d") . "\n"; echo "Hours: " . $diff->format("%h") . "\n"; echo "Minutes: " . $diff->format("%i") . "\n"; echo "Seconds: " . $diff->format("%s") . "\n"; 
+5
source share

The time() function returns the same value worldwide. Its return value is independent of the local time zone.

To convert the time value to your local time, call the localtime() function.

+1
source share

All Articles