如何将 Ada.Real_TIme.Time 转换为字符串?

发布于 2024-09-04 04:16:00 字数 158 浏览 1 评论 0原文

我想写一个 Ada.Real_Time.Time 在一个文件中,

我该怎么做?

谢谢

I would like to write a Ada.Real_Time.Time in a file,

How can I do that?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

看轻我的陪伴 2024-09-11 04:16:00

您可以使用 Ada.Real_Time.SplitAda.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'ImageDuration'Image 转换为 String

但是你想要这个字符串有什么用呢?如果要比较单次运行中事情发生的时间,那很好,但是语言定义中没有任何内容可以说明纪元是什么时候;例如,它可能是计算机上次启动的时间。

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.

来世叙缘 2024-09-11 04:16:00

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

且行且努力 2024-09-11 04:16:00

调用 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.

未蓝澄海的烟 2024-09-11 04:16:00

如果您不需要它作为可读文本,而只是希望将其保存到文件中,您可以尝试使用流输出属性('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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文