1

I have a problem with convert string datetime to timestamp in php.

$time = strtotime('2012-12-28 01:02:43');

echo $time; //it returns 1356627763

when I convert that integer value back to datetime it isn't correct (28/12/2012 00:02:43). Basically, it's late 1 hour.

my_format_datetime(strtotime('2012-12-28 01:02:43'));

Below is my my_format_datetime function :

> function my_format_datetime($unix)
>         {
>             if ($unix == '' || !is_numeric($unix))
>             {
>                     $unix = strtotime($unix);
>             }
>             else
>             {
>                 $timezone = 3600*(DEFAULT_GMT + date("0"));
>                 $unix = gmdate("d/m/Y H:i:s", $unix + $timezone);
>             }
>             
>             return $unix;
>         }

But when I convert using time() function it's correct.

Please help me. Thanks so much.

4
  • 3
    what is the value to DEFAULT_GMT Commented Dec 28, 2012 at 2:15
  • $timezone = 3600*(DEFAULT_GMT + date("0")); My guess would be the issue is with this. Commented Dec 28, 2012 at 2:16
  • Try this: stackoverflow.com/questions/7950854/… Commented Dec 28, 2012 at 3:36
  • DEFAULT_GMT is the timezone value (Exp: for my location is 7) Commented Dec 28, 2012 at 7:02

1 Answer 1

1

Set your local time zone. You can do it in php script by using date_default_timezone_set() .http://php.net/manual/en/function.date-default-timezone-set.php

or you can do it in php.ini configuration by changing the date.timezone value which defaults to UTC.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. I've mistaken timezone between local and global time.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.