CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

UnitsTime

time HMS

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 1.17
sub units 0.00
add a commercial licence to your cart
0
viewed 2360 times and licensed 27 times

Converts a fractional part of a serial Julian date and time into hours, minutes and seconds.

Controller: CodeCogs  Contact Controller
+View version details
Contents hide toc
buy now     get GPL     add to cart

Interface

#include <codecogs/units/time/timehms.h>

using namespace Units::Time;

void timeHMS (double nTime, int &Hours, int &Minutes, int &Seconds)
Converts a fractional part of a serial Julian date and time into hours, minutes and seconds.
void timeHMS (const char* Time, int &Hours, int &Minutes, int &Seconds)
Extracts the components of a time (hours, minutes, seconds) from a text string

Function Documentation

 
voidtimeHMSdoublenTime
int& Hours
int& Minutes
int& Seconds )
This function converts the fractional part of a serial Julian date and time into Hours, Minutes and Seconds, thereby performing the inverse of time. For the Gregorian calendar this conversion is achieved using:

a=Time - int(Time)
b=24*3600*a
Hours=int \left ( \frac{b}{3600} \right )
Minutes=int \left ( \frac{b\ mod\ 3600}{60} \right )
Seconds=int \left ( b\ mod\ 60 \right )

See:

The opposite of this function is time
Example 1:
#include <stdio.h>
#include <codecogs/units/time/timehms.h>
 
int main()
{
  for(double i=-0.5;i<=2;i+=0.1)
  {
    int h,m,s;
    Units::Time::timeHMS(i, h,m,s);
    printf("\n %02d:%02d:%02d", h, m, s);
  }
  return 0;
}
Output:
12:00:00
14:24:00
16:48:00
19:12:00
21:36:00
00:00:00
02:24:00
04:48:00
07:12:00
09:36:00
12:00:00
14:24:00
16:48:00
19:12:00
21:36:00
00:00:00
02:24:00
04:48:00
07:12:00
09:36:00
12:00:00
14:24:00
16:48:00
19:12:00
21:36:00
Parameters:
nTimecontains a time as a fraction of a day. The whole part of this number is ignored, so it could represent either days in a Julian or Gregorian calendar.
Hoursis a location (passed by reference) into which is placed the year.
Minutesis a location (passed by reference) into which is placed the month.
Secondsis a location (passed by reference) into which is placed the day.
Authors:
Will Bateman (Nov 2004)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


 
voidtimeHMSconst char*Time
int& Hours
int& Minutes
int& Seconds )
This function uses a number of simple rules to extract the most likely time from a text string, returning the individual elements (Hours, Minutes and Seconds) of the date. Unlike the Excel version this function is extremely forgiving, it will therefore interpret most date forms and will not return an error.
Example 2:
This example is intended to illustrates the type of times that can be processed, rather than to being functional (see time for a more functional examples).
#include <stdio.h>
#include <codecogs/units/time/time.h>
 
void main()
{
  int h,m,s;
  timeHMS("10pm", h,m,s);               // 22:00:00
  timeHMS("10:12pm", h,m,s);            // 22:12:00
  timeHMS("4am40/34", h,m,s);           // 04:40:34
  timeHMS("2,3,4", h,m,s);              // 02:03:04
  timeHMS("12@31@4", h,m,s);            // 12:31:04
  timeHMS("16:5:04pm", h,m,s);          // 28:05:04
}

Note:
This function can extract an illegal time, e.g. timeHMS("14 70 65 pm",h,m,s) will return the hour=26, minutes=70 and seconds=65. To be confident of having a legitimate date, use time instead, e.g. time("31 February 2004") will return a day fraction of ~1.132697 which equals 03:11:05 of the next day.
Parameters:
Timeis a text string that contains the time, with the following attributes:
Hoursis a location (passed by reference) into which is placed the hours of Time.
Minutesis a location (passed by reference) into which is placed the minutes of Time.
Secondsis a location (passed by reference) into which is placed the seconds of Time.
Authors:
Will Bateman (Nov 2004)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2010-03-14 17:11:12

Valid CSS!   Valid XHTML 1.0 Transitional