Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to get time in seconds from localtime(time) to next 21st date of the month?

by poolpi (Hermit)
on Feb 06, 2009 at 08:36 UTC ( [id://741830]=note: print w/replies, xml ) Need Help??


in reply to How to get time in seconds from localtime(time) to next 21st date of the month?

Two examples. (didactical purpose)

#!/usr/bin/perl use strict; use warnings; use v5.10.0; use Time::Piece; use Time::Seconds; use DateTime; my $dt = DateTime->now( time_zone => 'floating' ); my $next = { mon => ( $dt->mday >= 21 ? ( $dt->mon + 1 ) % 12 : $dt->mon ), year => ( ( $dt->mon == 12 and $dt->mday >= 21 ) ? $dt->year + 1 : $dt-> +year ), day => 21, hms => '12:00:00' }; $next->{'dt'} = DateTime->new( year => $next->{'year'}, month => $next->{'mon'}, day => $next->{'day'}, hour => substr( $next->{'hms'}, 0, 2 ) ); my $t = localtime; print Time::Seconds->new( Time::Piece->strptime( sprintf( "%s-%s-%sT%s", $next->{'year'}, $next->{'mon'}, $next->{'day'}, $next->{' +hms'} ), "%Y-%m-%dT%T" ) - $t )->seconds, "\n"; print $next->{'dt'}->subtract_datetime_absolute($dt)->seconds, "\n"; # Output : # 1308641 # 1308641
  • Comment on Re: How to get time in seconds from localtime(time) to next 21st date of the month?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found