Altera Home Page
Literature Licensing
Buy On-Line Download

  Home   |   Products   |   Support   |   End Markets   |   Technology Center   |   Education & Events   |   Corporate   |   Buy On-Line  
  Knowledge Database   |   Devices   |   Design Software   |   Intellectual Property   |   Reference Designs   |   Design Examples   |   mySupport  

 Products
      MAX/MAX II
      Stratix/Stratix GX
      Nios II
  
 Functionality
      Arithmetic
      Memory
      Bus & I/O
      Logic
      Interfaces & Peripherals
      DSP
      Communications
      PLL & Clocking
  
 Design Entry
      Quartus II Project
      Tcl
      VHDL
      Verilog HDL
      C Code Examples
      DSP Builder
      TimeQuest
   On-Chip Debugging
  
 Simulation Tools
      Mentor Graphics ModelSim
      Cadence NCsim
      Synopsys VCS
  
 Legacy Examples
      Graphic Editor
      AHDL
  

Quartus II Tcl Example: Date & Time Formatting

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 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.

%% The % sign
%a Abbreviated weekday name (Mon, Tue, etc.)
%A Full weekday name (Monday, Tuesday, etc.)
%b Abbreviated month name (Jan, Feb, etc.)
%B Full month name
%c Locale specific date and time
%d Day of month (01 - 31)
%H Hour in 24-hour format (00 - 23)
%I Hour in 12-hour format (00 - 12)
%j Day of year (001 - 366)
%m Month number (01 - 12)
%M Minute (00 - 59)
%p AM/PM indicator
%S Seconds (00 - 59)
%U Week of year (00 - 52), Sunday is the first day of the week
%w Weekday number (Sunday = 0)
%W Week of year (00 - 52), Monday is the first day of the week
%x Locale specific date format
%X Locale specific time format
%y Year without century (00 - 99)
%Y Year with century (e.g. 1990)
%Z Time zone name

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

Design Examples Disclaimer

These design examples may only be used within Altera Corporation devices and remain the property of Altera. They are being provided on an “as-is” basis and as an accommodation; therefore, all warranties, representations, or guarantees of any kind (whether express, implied, or statutory) including, without limitation, warranties of merchantability, non-infringement, or fitness for a particular purpose, are specifically disclaimed. Altera expressly does not recommend, suggest, or require that these examples be used in combination with any other product not provided by Altera.

  Please Give Us Feedback