Solved

Convert secs to time

Posted on 2004-09-14
2
278 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
Comment Utility
why not just use:

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

Expert Comment

by:snoyes_jw
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

762 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

6 Experts available now in Live!

Get 1:1 Help Now