Quartus® II Tcl Example: Date & Time Formatting

author-image

By

You can use the Tcl command clock seconds to return the current time and clock format to generate a custom-formatted date time string.

The clock format command accepts an optional argument named -format that specifies a string that controls how the date time string is formatted. You can specify date and time keywords that get replaced with specific parts of the current date and time.

Here's an example of the command that generates a date time string with the following elements, in this order:

  1. Four digit year
  2. Two digit month (01-12)
  3. Two digit day (01-31)
  4. Two digit hour in 24-hour format (00-23)
  5. Two digit minute (00-59)
  6. Two digit seconds (00-59)

clock format [clock seconds] -format {%Y %m %d %H %M %S}

That command generates this string:

2005 01 10 15 16 55

Here is a table of formatting strings you can use with the clock format command.

Examples

Here are other examples of the output for different format strings.

Example 1

clock format [clock seconds] -format {%b. %d, %Y}

Jan. 10, 2005

Example 2

clock format [clock seconds] -format {%I:%M:%S %p}

03:21:01 PM