Solved

Convert secs to time

Posted on 2004-09-14
2
279 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

937 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now