{"id":45,"date":"2011-10-25T09:59:21","date_gmt":"2011-10-25T09:59:21","guid":{"rendered":"http:\/\/www.sandykadam.com\/?p=45"},"modified":"2012-01-03T12:11:43","modified_gmt":"2012-01-03T12:11:43","slug":"seconds-to-string-in-php","status":"publish","type":"post","link":"https:\/\/www.sandykadam.com\/blog\/programming-stuff\/php\/seconds-to-string-in-php\/","title":{"rendered":"Seconds to String"},"content":{"rendered":"<p>This function will return the duration of the given time period in days, hours, minutes and seconds.<\/p>\n<p>e.g. secondsToStr(1234567) would return &#8220;14 days, 6 hours, 56 minutes, 7 seconds&#8221;<br \/>\n[code type=php]<br \/>\n&lt;?php<br \/>\nfunction secondsToStr($secs) {<br \/>\nif($secs&gt;=86400){$days=floor($secs\/86400);$secs=$secs%86400;$r=$days.&#8217; day&#8217;;if($days&lt;&gt;1){$r.=&#8217;s&#8217;;}if($secs&gt;0){$r.=&#8217;, &#8216;;}}<br \/>\nif($secs&gt;=3600){$hours=floor($secs\/3600);$secs=$secs%3600;$r.=$hours.&#8217; hour&#8217;;if($hours&lt;&gt;1){$r.=&#8217;s&#8217;;}if($secs&gt;0){$r.=&#8217;, &#8216;;}}<br \/>\nif($secs&gt;=60){$minutes=floor($secs\/60);$secs=$secs%60;$r.=$minutes.&#8217; minute&#8217;;if($minutes&lt;&gt;1){$r.=&#8217;s&#8217;;}if($secs&gt;0){$r.=&#8217;, &#8216;;}}<br \/>\n$r.=$secs.&#8217; second&#8217;;if($secs&lt;&gt;1){$r.=&#8217;s&#8217;;}<br \/>\nreturn $r;<br \/>\n}<\/p>\n<p>?&gt;<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This function will return the duration of the given time &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[24],"tags":[37],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-php","tag-php-2"],"aioseo_notices":[],"views":580,"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p25uYH-J","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":4,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sandykadam.com\/blog\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}