简体   繁体   中英

How can you print an Ada.Calendar.Time variable in Ada?

Need to know how to print a Time variable in Ada. I assume there is no portable way because Time is implementation defined. I've already seen the GNAT.Calendar.Formatting package available under GNAT, I'd also be interested in a GHS for VME.

See package "Ada.Calendar.Formatting" function "Image" for Ada2005. If you have an Ada95 compiler you could and this package isn't available, try my implementation from here

This was written using GNAT 3.15p, so pretty old.

Here's an example that displays the date and time using the GNAT.Calendar.Time_IO package:

with ada.calendar;
with gnat.calendar.time_io;

procedure display_time is
begin
  gnat.calendar.time_io.put_time(ada.calendar.clock, "Date: %Y/%m/%d Time: %H:%M:%S");
end display_time;

Date/time format options are available here: https://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT.Calendar.Time_IO

Sure, time output can be portable, Ada.Calendar contains standard functions that extract the components of a time value, so it's straightforward to put together your own conversion package.

For example, here's one . One just needs to either create a minor addition to create a "Formatted_Time" record for a given Time value (see the package's Get_Time() function for guidance), or make Main_Formatter() visible in the package spec.

通常,我要做的是使用Calendar.Split,然后在我关心的零件上做一个“图像”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM