Ok, so I was able to figure this out.
So I used the same exact formula from my OP and did the total seconds into the past minus 'time'.
This was almost exactly what I wanted, but no matter what I put for a length into the past the
output was ALWAYS showing 4 Hours off from what it should have been...
I then realized that I should have been using "localtime()" instead of "gmtime()". I switched them
up and now its working like a charm!!
Here's how to do it if anyone ever gets stuck trying to calculate a Date AND Time into the past:
For Example --> I want "2 Days, 12 Hours, 1 Minute, and 20 Seconds" into the past...
From my Linux CMD Prompt: FYI... The integer '216080' is the total seconds into the past
### This will print the date and Time in a readable format (i.e. mm/dd/yyy hh:mm:ss in 24-Hour Format)...
perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%m/%d/%Y %T", localtime( time-216080 )); print "$_n_days_ago\n"'
### Now what I wanted for MY output is (i.e. "$seconds, $minutes, $hours, $mday, $month, $year")
# I wanted it like this so I could get the UNIX Timestamp of that Past Date and Time by using those values from its output...
perl -e 'use POSIX 'strftime'; $_n_days_ago = strftime("%S, %M, %k, %d, %m, %Y", localtime( time-216080 )); print "$_n_days_ago\n"'
Thanks,
Matt
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.