Time Formatting Parsing in Fortran
Fortran supports time formatting and parsing via built-in functions and modules.
In this Fortran example, we demonstrate time formatting and parsing using built-in functions and custom routines. Here’s a breakdown of the code:
We use the
date_and_time
intrinsic subroutine to get the current date and time.We format the time according to ISO 8601 (similar to RFC3339) using Fortran’s formatted write statement.
For time parsing, we create a custom subroutine
parse_time
that reads a formatted time string and extracts its components.We demonstrate custom time formatting using Fortran’s formatted write statements.
For purely numeric representations, we use Fortran’s formatted write statements with the extracted components of the time value.
Note that Fortran doesn’t have built-in constants for time formats like RFC3339. Instead, we manually construct the format strings. Also, Fortran’s time handling capabilities are more limited compared to some other languages, so some advanced features may require additional libraries or more complex custom routines.
To run this program, save it as time_formatting_parsing.f90
and compile it using a Fortran compiler:
This will output the formatted and parsed times according to the program.