Is there any better method of displaying wall clock time except using walltimestamp variable?

StackOverflow https://stackoverflow.com/questions/21084922

  •  27-09-2022
  •  | 
  •  

Question

I want to print the time when a probe is fired. After checking the Dtrace documents, I find the built-in variable: walltimestamp. And the Dtrace script likes this:

pid$1::func:entry
{
    trace(walltimestamp);
}  

But the walltimestamp is "The current number of nanoseconds since 00:00 Universal Coordinated Time, January 1, 1970.", so the output likes "1389583988106535481". I think this isn't easy for user to understand and want the output likes "Mon Jan 13 00:00:00 2014". I have searched whether Dtrace provide functions like ctime in C programming language, but nothing found.

Does anyone need to implement a function like ctime by himself? Or Is there any better method to display the time?

Était-ce utile?

La solution

Use printf():

# dtrace -qn 'BEGIN {printf("%Y\n", walltimestamp); exit(0)}'
2014 Jan 13 08:37:56

#
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top