Use timeformat:
...
$timeformat(-9, 3, "ns", 8);
//$timeformat params:
//1) Scaling factor (–9 for nanoseconds, –12 for picoseconds)
//2) Number of digits to the right of the decimal point
//3) A string to print after the time value
//4) Minimum field width
$display("%t", $realtime);