Reputation: 3986
I have date format like this (2018-08-05T06:22:30Z). I need to convert it to dd-mm-yyyy hh:mm:ii format.
I have tried this so far:
$dt ="2018-08-05T06:22:30Z";
$dt1 = date('d-m-Y HH:mm:ii', strtotime($dt));
Output of above code is 05-08-2018 0202:0808:2222.
How can I convert it to dd-mm-yyyy hh:mm:ii
format?
Upvotes: 1
Views: 2889
Reputation: 57121
Your time format is doubling up the format letters - HH:mm:ii
you are also confusing the Month (m) and the minutes (i), it should be H:i:s
which gives...
05-08-2018 07:22:30
Upvotes: 3
Reputation: 3772
Change $dt1 to be
$dt1 = date('d-m-Y H:i:s', strtotime($dt));
You should check PHP Date to see the format parameters. The ones I changed in your code were as follows;
i - which gets you the minutes with leading zeros
s - which gets you the seconds with leading zeros
Upvotes: 1