Display time using $Display in System verilog/UVM

//`timescale 1ns/100fs 

module tim(); 
timeunit 1ns;
timeprecision 100fs;
reg i; 

initial 
begin 
i=0; 
#7; 
i=1; 
$display("STATEMENT 1 :: time is %0t",$time); 
#7; 
$finish; 
end 
 
initial $printtimescale();

endmodule

In the above code output of $display is “time is 70000”. if i want to print the time with timeunit , is there any way i can do the same without printing ns/ps from the display statement.

In reply to samir singh:

The $timeformat systemtask can be used for this. More details in the LRM.
E.g.


initial
//shall print %t with scaled in ns (-9), with 2 precision digits, and would print the " ns" string
  $timeformat(-9, 2, " ns", 20);

In reply to ayehia:

Can’t it be done with $display. i saw in my env it was printing the timeunit but not able to figure out how is it printing timeunit

In reply to samir singh:

$timeformat affects how the %t is printed in $display. So you specify $timeformat only once as shown above in an initial block, then any $display having %t will function as you described. By default %t will print time w.r.t. the smallest precision in the simulation cluster with no time units. However you can change the default as above. If you added the above $timeformat code in your example above, your $display will print time as “7.00 ns” instead of “70000”. Does this answer your question?

In reply to ayehia:
Maybe this was already understood, but just to clarify, %t can be used by any of the print formatting tasks, not just $display. UVM users should not be using $display.

In reply to ayehia:

thanks , got the concept.

In reply to dave_59:

thank you Dave.