0

How we can use current time instead of '15:33:56' now() Function or time() but it gives wrong time in AM and PM.

<?php


function twentyfourToTwelve($time)
{
    return date('g:i:sa', strtotime($time));
}


 /*** Example usage ***/
 echo twentyfourToTwelve('15:33:56').'<br />';

 echo twentyfourToTwelve('15:33').'<br />';

 echo twentyfourToTwelve('15.12').'<br />';

 echo twentyfourToTwelve('2:33:56').'<br />';

 echo twentyfourToTwelve('15:33').'<br />';
?>
3
Contributors
11
Replies
14
Views
7 Years
Discussion Span
Last Post by ayesha789
0
function twentyfourToTwelve($time)
{
    return date('g:i:s a', strtotime($time . " UTC"));
}
 
 
 /*** Example usage ***/
 echo twentyfourToTwelve('15:33:56');

This work?

0

This show 8:33:56 pm in result.
Its wrong.
I need to show time in my website in 12 Hours Format so please tell me.

0

Congrats adatapost
i want to show time on my website .
pakistan standard time with 12 hours time.
please tell me how to.

0

For **** sakes Ayesha, if you'd said you wanted Pakistan time, that would have been straight forward - we ain't got no crystal balls you know. Look at the php documentation on setting times. Sheesh...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.