Solved

Convert secs to time

Posted on 2004-09-14
2
281 Views
Last Modified: 2013-12-12
I am trying to write a function to convert seconds to time format (hh:mm AM/PM)


function convertsecs ( $mysec )
{

      $timesec = bcmod($mysec,60);
      $timemin = bcmod(($mysec - $timesec),3600) / 60;
      $timehour = ($mysec - ($timemin*60)) / 3600;
      $newtime = date("h m", mktime($timehour,$timemin));

      return $newtime;
}

Is this right? If not what am I doing wrong?
0
Comment
Question by:anusha
  • 2
2 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 50 total points
ID: 12058552
why not just use:

return date("h:i A", strtotime("0:0:" . $mysec));
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 12058568
Even if your math is right, part of your problem may be that "m" in the date function means month of the year, not minute of the hour.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question