Invoke the Ada.Real_Time.Split() function, which converts a Time to a Seconds_Count and a Time_Span. The Seconds_Count value is the number of seconds elapsed since the epoch, and the Time_Span value is the number of (very small) Time_Units after that last second. See D.8 Monotonic Time (29) for details.
Seconds_Count is publicly visible in the package, and the Time_Span can be converted to a Duration via To_Duration().
Note that you can invert the process and use Time_Of() to reconstruct a Time value.
You can use Ada.Real_Time.Split to convert an Ada.Real_Time.Time into (a) the number of seconds since the epoch, type Ada.Real_Time.Seconds_Count and (b) the fractional part, type (private) Ada.Real_Time.Time_Span; and you can use Ada.Real_Time.To_Duration to convert the fractional part into a Duration.
You can then use Ada.Real_Time.Seconds_Count'Image and Duration'Image to convert to String.
But what do you want the string for? If it's to compare when things happened in a single run, fine, but there's nothing in the language definition to say when the epoch was; it could be the time when the computer was last booted, for example.
Package Ada.Real_time doesn't provide a method for the direct format.
I'd advise you to look at Ada.Calendar.Formatting.
You have a method Clock like in Ada.Real_time.
Indeed, there is a method Image(parameters : Time), which returns a String.
Invoke the Ada.Real_Time.Split() function, which converts a Time to a Seconds_Count and a Time_Span. The Seconds_Count value is the number of seconds elapsed since the epoch, and the Time_Span value is the number of (very small) Time_Units after that last second. See D.8 Monotonic Time (29) for details.
Seconds_Count is publicly visible in the package, and the Time_Span can be converted to a Duration via To_Duration().
Note that you can invert the process and use Time_Of() to reconstruct a Time value.
You can use
Ada.Real_Time.Split
to convert anAda.Real_Time.Time
into (a) the number of seconds since the epoch, typeAda.Real_Time.Seconds_Count
and (b) the fractional part, type (private)Ada.Real_Time.Time_Span
; and you can useAda.Real_Time.To_Duration
to convert the fractional part into aDuration
.You can then use
Ada.Real_Time.Seconds_Count'Image
andDuration'Image
to convert toString
.But what do you want the string for? If it's to compare when things happened in a single run, fine, but there's nothing in the language definition to say when the epoch was; it could be the time when the computer was last booted, for example.
Package Ada.Real_time doesn't provide a method for the direct format.
I'd advise you to look at Ada.Calendar.Formatting. You have a method Clock like in Ada.Real_time. Indeed, there is a method Image(parameters : Time), which returns a String.
For more details : Package: Ada.Calendar.Formatting
If you don't need it as readable text, but just want it saved to a file, you could try using the stream output attribute (
'Write
)