I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 1.40
sub units 0.00
+
0
UnitsTime

time HMS

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

Interface

C++

TimeHMS

 
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:

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

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

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


TimeHMS

 
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
}

  • Any separator that isn't numeric, alphabetic or '-' can be used (i.e. non alphanumeric). Therefore you can have negative hours, minute or seconds through the use of the negative sign.
  • Only the first 3 terms will be processed. If less than 3 terms are specified, then zero is used for the missing values.
  • The time elements are always expected to be in the order of: hours, minutes, seconds
  • By default a 24hr clock is assumed, however if either "am" or "pm" in specified in any part of the string, then the first number is assumed to be part of a 12 hour clock from either the morning or afternoon, respectively. N.B. 13pm would return an hour=25 (i.e. 1am in the next day).

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

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

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