Search code examples
perldatetime

Perl DateTime nanoseconds always 0


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

Solution

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