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 />';
?>

Please tell me how to show time in !2 Hours Format.
Thanks.

Member Avatar

diafol

How's this? date("g:i:s a", strtotime("{$time} UTC"))

What u said?
Please explain Dear.

Member Avatar

diafol

function twentyfourToTwelve($time)
{
    return date('g:i:s a', strtotime($time . " UTC"));
}
 
 
 /*** Example usage ***/
 echo twentyfourToTwelve('15:33:56');

This work?

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.

What is wrong with ardav's post?
12 Hour format is 01:01:01 PM
24 Hour format is 13:01:01

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

Please tell me about Showing Time in 12 Hours Format.

Member Avatar

diafol

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...

I got the solution using Javascript. Thanks.