HomeForumResearchGuide
This program showss how we can get the current system date and time, and pause for some time.

Create a new file Main.dn and open it in a text editor. We're going to use the Calendar interface, the command-line output interface, the IntUtil interface to help us print integers, and the Timer interface to pause a thread. We'll start with this code in our new file:

component provides App requires io.Output out, data.IntUtil iu,
				time.Calendar ic, time.Timer timer {

}

The App interface has one function called main. Any executable component will implement App, indicating it has a main method that Dana can launch.

We now need to implement our App interface, which we'll do like this:

component provides App requires io.Output out, data.IntUtil iu,
				time.Calendar ic, time.Timer timer {

int App:main(AppParam params[])
	{
	while (true)
		{
		DateTime t = ic.getTime()

		out.println("date/time: $(t.year)-$(t.month)-$(t.day) $(t.hour):$(t.minute):$(t.second).$(t.millisecond)")

		timer.sleep(1000)
		}

	return 0
	}

}

This program uses an infinite loop to get the current date and time from the Calendar instance, then pause the program for 1,000 milliseconds, before perfoming the loop again.

We can now compile the program using the Dana compiler. Open a command-prompt in the directory containing your source code file and type:

dnc Main.dn

And pressing enter. This will compile your component.

We run the program using Dana's interpreter by typing:

dana Main

And pressing enter. You should see the current date and time printed every second. Press Ctrl + C to quit the program.

The full list of standard interfaces that you can use in requires directives can be viewed at the Dana API pages along with documentation of each one. In this example we used: