24 Hours to 12 Hours in PHP

Thread Solved

Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

24 Hours to 12 Hours in PHP

 
0
  #1
Jul 1st, 2009
How we can use current time instead of '15:33:56'
now() Function or time() but it gives wrong time in AM and PM.

  1. <?php
  2.  
  3.  
  4. function twentyfourToTwelve($time)
  5. {
  6. return date('g:i:sa', strtotime($time));
  7. }
  8.  
  9.  
  10. /*** Example usage ***/
  11. echo twentyfourToTwelve('15:33:56').'<br />';
  12.  
  13. echo twentyfourToTwelve('15:33').'<br />';
  14.  
  15. echo twentyfourToTwelve('15.12').'<br />';
  16.  
  17. echo twentyfourToTwelve('2:33:56').'<br />';
  18.  
  19. echo twentyfourToTwelve('15:33').'<br />';
  20. ?>
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: 24 Hours to 12 Hours in PHP

 
0
  #2
Jul 1st, 2009
Please tell me how to show time in !2 Hours Format.
Thanks.
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,023
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 131
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: 24 Hours to 12 Hours in PHP

 
0
  #3
Jul 1st, 2009
How's this?

date("g:i:s a", strtotime("{$time} UTC"))
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: 24 Hours to 12 Hours in PHP

 
0
  #4
Jul 1st, 2009
What u said?
Please explain Dear.
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,023
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 131
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: 24 Hours to 12 Hours in PHP

 
0
  #5
Jul 1st, 2009
  1. function twentyfourToTwelve($time)
  2. {
  3. return date('g:i:s a', strtotime($time . " UTC"));
  4. }
  5.  
  6.  
  7. /*** Example usage ***/
  8. echo twentyfourToTwelve('15:33:56');

This work?
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: 24 Hours to 12 Hours in PHP

 
0
  #6
Jul 2nd, 2009
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.
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,668
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 478
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: 24 Hours to 12 Hours in PHP

 
0
  #7
Jul 2nd, 2009
What is wrong with ardav's post?
12 Hour format is 01:01:01 PM
24 Hour format is 13:01:01
Last edited by adatapost; Jul 2nd, 2009 at 2:27 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: 24 Hours to 12 Hours in PHP

 
0
  #8
Jul 2nd, 2009
Congrats adatapost
i want to show time on my website .
pakistan standard time with 12 hours time.
please tell me how to.
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 207
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: 24 Hours to 12 Hours in PHP

 
0
  #9
Jul 2nd, 2009
Please tell me about Showing Time in 12 Hours Format.
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,023
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 131
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

Re: 24 Hours to 12 Hours in PHP

 
0
  #10
Jul 2nd, 2009
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...
Happy Humbugging Christmas
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC