decode_time(+TimeNumber, ?Hour, ?Min, ?Sec)

Convert a time number back to Hour, Minutes and Seconds values. A time number is the number of seconds since 0:0:0.

Because time numbers are integers they can be used in arithmetic expressions. For instance, add 2 minutes to a time. First convert the time to a time number, add 120 to the time number and then convert the time number back to a Hour:Minute:Second representation with decode_time/4.

This predicate is located in the file 'datetime.txt', use ensure_loaded/1 to include this file.

see also: age/7 day_number/4 day_of_week/2 datetime module decode_date/4 decode_datetime/7 encode_date/4 encode_datetime/7 encode_time/2 encode_time/3 encode_time/4 ensure_loaded/1 first_week/2 leap_year/1 length_month/3 monday_of_week/3 monday_of_week/5 next_week/4 num_weeks_in_year/2 prev_week/4 reverse_day_number/4 start_of_week/3

Example
decode_time(45, H, M, S). succeeds, the time number is decoded and the values of the variables after unification are:
H = 0
M = 0
S = 45
decode_time(12000, H, M, S). succeeds, the values of the variables after decoding are:
H = 3
M = 20
S = 0
decode_time(12000, 3, 20, 1). fails, because the decoded number of seconds is 0 and this value does not unifiy with 1

 

Exceptions  
The TimeNumber parameter is not an integer a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect parameter
The Hour, Min or Sec parameters are not an integers nor variables a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect parameter

 

 

info@trinc-prolog.com