Epoch in Fortran
Our program demonstrates how to get the number of seconds, milliseconds, or nanoseconds since the Unix epoch in Fortran.
In this Fortran program:
We use the
system_clock
subroutine to get the current time. This subroutine returns the number of clock ticks since an arbitrary time in the past.We calculate the seconds since the epoch by dividing the clock count by the clock rate.
We print the time in seconds, milliseconds, and nanoseconds since the epoch.
Note that Fortran doesn’t have built-in functions to directly get the Unix epoch time like some other languages do. The system_clock
function provides a way to get the current time, but the exact start point (epoch) can vary between systems. For more precise and standardized time handling, you might need to use external libraries or system-specific functions.
To compile and run the program:
The actual numbers you see will depend on the current time when you run the program.
Fortran doesn’t have built-in functions to convert between different time representations as easily as some other languages. For more complex time manipulations, you might need to implement your own functions or use external libraries.
Next, we’ll look at another time-related task: time parsing and formatting.