1

Using the following code I'm getting the output as mentioned below.

echo $date = new date('c', strtotime('2017-03-14T22:30:00.000Z'));

Current Output: 2017-03-15T04:30:00+06:00

Expected Output: 2017-03-15 10:30:00 AM

How could I do it using PHP?

1
  • 1
    Edit your php.ini file, then change / add following date.timezone directive: date.timezone = "Asia/Dhaka" then restart php service Commented Mar 14, 2017 at 8:35

2 Answers 2

1

Please try this: echo $date = date('Y-m-d H:i:s A', strtotime('2017-03-14T22:30:00.000Z'));

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

2 Comments

This is working, but I also need to add +6 hours to adjust my local time and it will become 2017-03-15 10:30:00 AM . My timezone is Asia/Dhaka. Can you please suggest me to make as I expected?
Please try this url for more details: stackoverflow.com/questions/19616822/…
0

I would suggest to use DateTime

$d = new DateTime('2017-03-14T22:30:00.000Z');
echo $d->format('Y-m-d H:m:s');
//2017-03-14 22:03:00

$d->setTimezone(new DateTimeZone('Asia/Dhaka'));
echo $d->format('Y-m-d H:m:s');
//2017-03-15 04:03:00

Also, it seems to me that Asia/Dhaka is in fact UTC+6 so what you are after would be 2017-03-15T04:30:00, not 2017-03-15T10:30:00 (here the offset would be 12 hours)?

Comments

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.