Closed d5ve closed 9 years ago
Hi Dave,
The strftime()
implementation has two conversion specifications for formatting fractional seconds, %f
and %N
. If you want to unconditionally output fractional seconds as nanoseconds, use the '.%9N'
specification.
Example:
$ perl -MTime::Moment -lwe "print Time::Moment->from_epoch(1439337975, 0)->strftime('%FT%X.%9NZ')"
2015-08-12T00:06:15.000000000Z
$ perl -MTime::Moment -lwe "print Time::Moment->from_epoch(1439337975, 1)->strftime('%FT%X.%9NZ')"
2015-08-12T00:06:15.000000001Z
chansen
Doh, I completely missed the "Replaced by the fractional second including the preceding decimal point or by an empty string if no fractional seconds are present." bit in the docs for %f
.
%N
is indeed exactly what I need here, thanks.
Hi,
I'm trying to use strftime() to output ISO 8601
<date>T<time>Z
values. It's quite an edge-case, but when the nanoseconds value is zero, strftime() doesn't zero-pad the fractional seconds.The two following one-liners show the difference in output beween 0 and 1 nanoseconds when strftime() is asked to pad fractional seconds to 9 digits.
Is this considered a bug?
Cheers,
Dave