bachx Posted June 6, 2007 Share Posted June 6, 2007 Hi, I want to print the time in this format: x Hours x Minutes x Seconds Is that possible in the date() function? Or do I need to code it myself? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/54440-how-to-display-time-in-this-format/ Share on other sites More sharing options...
per1os Posted June 6, 2007 Share Posted June 6, 2007 <?php // I doubt this will work $time = date("h hours i minutes s seconds", time(); echo $time; //if not try this. $time = date("h:i:s", time(); $time = explode(":", $time); echo $time[0] . " Hours " . $time[1] . " Minutes " . $time[2] . " Seconds"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54440-how-to-display-time-in-this-format/#findComment-269267 Share on other sites More sharing options...
Psycho Posted June 6, 2007 Share Posted June 6, 2007 Neither of those will work when they are both missing a closing paren. The first one won't work (tested), but the 2nd onw will. Here is another option. <?php $timeStamp = time(); //Or whatever time you want echo date('h',$timeStamp) . ' Hours ' . date('i',$timeStamp) . ' Minutes ' . date('s',$timeStamp) . ' Seconds'; ?> You can make this a one-liner if you are only showing current time by removing the $timestamp references <?php echo date('h') . ' Hours ' . date('i') . ' Minutes ' . date('s') . ' Seconds'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54440-how-to-display-time-in-this-format/#findComment-269276 Share on other sites More sharing options...
obsidian Posted June 6, 2007 Share Posted June 6, 2007 Here: <?php echo date('h \h\o\u\r\s i \m\i\n\u\t\e\s s \s\e\c\o\n\d\s'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54440-how-to-display-time-in-this-format/#findComment-269282 Share on other sites More sharing options...
Psycho Posted June 6, 2007 Share Posted June 6, 2007 Ah, I didn't think about escaping the characters. Much more efficient. Quote Link to comment https://forums.phpfreaks.com/topic/54440-how-to-display-time-in-this-format/#findComment-269284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.