2

How i can get nanosecond from DateTime in Perl?

I try

say DateTime->from_epoch(epoch => time)->nanosecond; # 0
say DateTime->from_epoch(epoch => time)->strftime('%9N'); # 0
Unknown.Vagrant
  • 252
  • 2
  • 12
  • 2
    Does this answer your question? [How to get system time in nano seconds in Perl?](https://stackoverflow.com/questions/26032541/how-to-get-system-time-in-nano-seconds-in-perl) – Rudedog Aug 27 '21 at 15:55

2 Answers2

5

time returns the number of (whole) seconds since the start of the unix epoch. Time::HiRes provides a version of time with better resolution.

ikegami
  • 367,544
  • 15
  • 269
  • 518
0

Note that Time::HiRes::time only gives answers in steps of 2**-22 seconds or 0.24µs. (For a full explanation, see https://stackoverflow.com/a/66487325/5781773)

Martin Kealey
  • 546
  • 2
  • 11