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.
发布评论
评论(4)
您可以使用
Ada.Real_Time.Split
将Ada.Real_Time.Time
转换为 (a) 自纪元以来的秒数,输入Ada.Real_Time。 Seconds_Count
和 (b) 小数部分,类型(私有)Ada.Real_Time.Time_Span
;您可以使用Ada.Real_Time.To_Duration
将小数部分转换为Duration
。然后,您可以使用
Ada.Real_Time.Seconds_Count'Image
和Duration'Image
转换为String
。但是你想要这个字符串有什么用呢?如果要比较单次运行中事情发生的时间,那很好,但是语言定义中没有任何内容可以说明纪元是什么时候;例如,它可能是计算机上次启动的时间。
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.
Ada.Real_time 包没有提供直接格式的方法。
我建议您查看 Ada.Calendar.Formatting。
您有一个类似于 Ada.Real_time 中的 Clock 方法。
事实上,有一个方法 Image(parameters : Time),它返回一个字符串。
欲了解更多详细信息:软件包:Ada.Calendar。格式设置
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
调用 Ada.Real_Time.Split() 函数,该函数将 Time 转换为 Seconds_Count 和 Time_Span。 Seconds_Count 值是自纪元以来经过的秒数,Time_Span 值是最后一秒之后的(非常小的)Time_Units 数。请参阅 D.8 单调时间 (29)细节。
Seconds_Count 在包中公开可见,并且 Time_Span 可以通过 To_Duration() 转换为 Duration。
请注意,您可以反转该过程并使用 Time_Of() 来重建 Time 值。
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.
如果您不需要它作为可读文本,而只是希望将其保存到文件中,您可以尝试使用流输出属性(
'Write
)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
)