Reputation: 483
I want to add the milliseconds to current time in perl. I wrote this code:
my $currentTime = DateTime->now(time_zone=>$timezone);
my $endTimeInMills = $details->{'msToEnd'};
my $dealEndTime = $currentTime->add(nanoseconds => ($endTimeInMills * 1000000) );
The problem i am facing is after adding the nanoseconds to current time i am seeing that 1 minutes is lost. Like after adding time should be 22:00 but it will show 21:59. Can anyone tell the issue?
Upvotes: 1
Views: 72
Reputation: 386541
Adding a sufficient number of nanoseconds will change the time as you expect.
use feature qw( say );
use DateTime qw( );
my $dt = DateTime->now( time_zone => 'local' );
say $dt->hms; # 23:10:10
$dt->add( nanoseconds => 2_000_000_000 );
say $dt->hms; # 23:10:12
No idea what problem you are having as you didn't demonstrate it.
Upvotes: 1