time2num


The time2num function returns a numeric time value in hours from a string like '04:35:14.45' or 04:35:14.45. Strings with enclosing ' ' are present in FITS image headers and are returned using CImage:KwdGetRaw.

NOTE:

You may wish to test if the string is a time value before calling this function to avoid the ambiguous results for time2num("00:00:00") and time2num(0).

Syntax

nHours = time2num( sString )

bullet.gif    sString is the target string.

bullet.gif    nHours is the time in units of hours.

bullet.gif    On failure, 0.0 is returned.

Example

The scripts below return the time value for several strings:

str = "'04:35:14.45'"

-- time string with ' '

if is_time( str ) then

 

  Printf("t = %.8f\n", time2num(str))

-- prints t = 4.58734722

end

 

 

 

str = "04:35:14.45"

-- time string without ' '

if is_time( str ) then

 

  Printf("t = %.8f\n", time2num(str))

-- prints t = 4.58734722

end

 

 

 

if is_time( "Johnny" ) then

-- not a time

  nHours = time2num( str)

 

  Printf("t = %.8f\n", nHours)

-- skipped because not a time

end

 

 

 

Printf("t = %.8f\n", time2num("Johnny"))

-- prints t = 0

Printf("t = %.8f\n", time2num(15.5))

-- prints t = 0

Related Topics

is_time

is_datetime

datetime2num

String Type Functions

 


Mira Pro x64 Script User's Guide, v.8.77 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.