Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

( #741830=categorized answer: print w/ replies, xml ) Need Help??

Q&A > dates and times > How to get time in seconds from localtime(time) to next 21st date of the month? contributed by poolpi

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 Answer: 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
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-08-22 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls