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

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

  •  27-09-2022
  •  | 
  •  

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?

有帮助吗?

解决方案

Use printf():

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

#
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top