Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
without using any module...
#!/usr/bin/perl use strict; use warnings; sub time_to_str { my ($sec, $min, $hour, $mday, $mon, $year) = localtime(shift); return sprintf "%04d%02d%02d%02d%02d%02d", $year+1900, $mon+1, $mday +, $hour, $min, $sec; } sub find_time { my $tstr = shift; my $max = 2**31; my $min = 0; while ($max != $min) { my $mid = int (($max + $min) / 2); my $midstr = time_to_str $mid; if ($tstr gt $midstr) { $min = $mid + 1; } else { $max = $mid; } } return $max; } sub add_seconds { my ($timestr, $seconds) = @_; my $time = find_time $timestr; return time_to_str($time + $seconds) } while (<DATA>) { next if /^\s*(?:#.*)?$/; my ($date, $seconds) = split; printf "%s + %ds = %s\n", $date, $seconds, add_seconds($date, $secon +ds); } __DATA__ # YYYYMMDDhhmmss seconds 20060413020000 900 20060413024500 900 20061231235700 900

In reply to Re: getting Date calculation in simpler way by salva
in thread getting Date calculation in simpler way by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-05-25 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?