3

How can I show the local date and time for Philippines?

<? php
    date_default_timezone_set('Asia/Manila');
    echo "<span style='color:red;font-weight:bold;'>Date: </span>". date('F j, Y g:i:a  ');
?>
3
  • Time zone offset: UTC + 8 hours
    – Roy M J
    Sep 18, 2014 at 5:53
  • remove the space between your php tag <?php date_default_timezone_set('Asia/Manila'); echo "<span style='color:red;font-weight:bold;'>Date: </span>". date('F j, Y g:i:a '); ?> Sep 18, 2014 at 5:56
  • it gives me 8hours advance... -_- Sep 18, 2014 at 6:14

2 Answers 2

11

You shouldn't add space between <? and php

<?php
date_default_timezone_set('Asia/Manila');
echo "<span style='color:red;font-weight:bold;'>Date: </span>". date('F j, Y g:i:a  ');
?>
4
  • i did that, but i want to set the local time... that code give Date: September 19, 2014 4:59:am i want Date: September 18, 2014 2:00pm Sep 18, 2014 at 5:57
  • There's nothing wrong with your code except what this answer suggests. See here eval.in/194864 Sep 18, 2014 at 6:01
  • @TuperEvangelista date_default_timezone_set('Asia/Manila'); has already set your timezone correctly
    – worldask
    Sep 18, 2014 at 6:03
  • I'm in China, I have the same timezone with you. Your code works fine on my computer, that's 2pm. Couldn't be sth else change your time setting?
    – worldask
    Sep 18, 2014 at 6:14
1

As @worldask already sad you shouldn't add space between those <? php . The rest of the code is good. The reason why you don't get the date you want, is that the server's time is different than you think it is. When the PHP engine adds 8 hours to his system date it gives you a good result. In order to check which is the current hour and debug your problem use the following code, then fix the system's date.

<?php
echo "Current timezone: ".date_default_timezone_get()."</ br>
      Current time: ".date("d-m-Y H:i:s");
?>
3
  • For sure there isn't something wrong with your code.
    – besciualex
    Sep 18, 2014 at 6:14
  • it gives me 8hours advance -_- Sep 18, 2014 at 6:15
  • @TuperEvangelista then the problem is with your system date. If you develop on your local machine and it has the correct date, then the problem stays in your php.ini file. Please set it up correctly. If you develop on a server adjust the date and time to your needs.
    – besciualex
    Sep 18, 2014 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.