We can use several methods to deal with the time and date in the D programing language. One of those methods is the Clock.currTime()
method from the standard library datetime
module.
The currTime
method of the Clock
class is a part of the datetime
module. The Clock.currTime()
method displays the current local time of the system at any point.
It only accepts one parameter, which is the preferred timezone.
Clock.currTime(tz)
tz
: This is the timezone based on the current time displayed.This function returns a date-time value.
The code below uses the date-time property of the year, day, and others to extract parts of the Clock.currTime
method’s return value. Anytime we hit the run button, the current time of the machine hosting this platform will be displayed. If this program is executed in your own machine, the system time of your machine will be displayed.
import std.datetime;import std.stdio;void main(){auto times = Clock.currTime(LocalTime());writeln(times) ;writeln("Year:",times.year);writeln("Month:",times.month);writeln("Day:",times.day);writeln("Hour:",times.hour);writeln("Minutes:",times.minute);writeln("Seconds:",times.second);}
datetime
and stdio
modules from the standard library.Clock.currTime()
is called to return the localtime
. This is saved in the times
variable.