sufocator
sufocator

Reputation: 39

How to get current year in ada

I am working on an ada homework and I don't understand how can I get the current year. I know that I have to use the Ada.Calendar package but I'm not sure how I can do this.

Upvotes: 0

Views: 169

Answers (1)

Jim Rogers
Jim Rogers

Reputation: 5031

Read section 9.6 of the Ada Reference Manual. http://www.ada-auth.org/standards/12rm/html/RM-9-6.html

You need to declare a variable of the type Time defined in the package Ada.Calendar. The function Clock, also described in the Ada.Calendar package returns the current time. Assign that value to the Time variable you defined.

The Ada.Calendar package also contains a function named Year which takes an instance of Time as its parameter and returns the Year number of that Time value.

with Ada.Calendar; use Ada.Calendar;
with Ada.Text_IO;  use Ada.Text_IO;

procedure Display_This_Year is
   Now : Time := clock;
begin
   Put_Line("This year is " & Year_Number'Image(Year(Now)));
end Display_This_Year;

Upvotes: 2

Related Questions