Solved

Convert secs to time

Posted on 2004-09-14
2
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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