How To Get a Formatted Date in Perl
1 2 3 |
use POSIX qw(strftime); my $stamp = strftime "%Y%m%d%H%M%S", localtime; my $stamp = strftime "%Y%m%d%H%M%S", gmtime; |
1 2 3 |
use POSIX qw(strftime); my $stamp = strftime "%Y%m%d%H%M%S", localtime; my $stamp = strftime "%Y%m%d%H%M%S", gmtime; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/sh DATE=`date` ( echo "From: Your Full Name <you@yourdomain.com>" echo "To: you@yourdomain.com" echo "Subject: AWS Instances Report for All Customers as of $DATE" cat <<EOT MIME-Version: 1.0 Content-Type: text/html Content-Disposition: inline <html> <body> <pre style="font: monospace"> EOT for profile in customer1 customer2 customer3; do for region in `aws ec2 describe-regions --output text | cut -f3`; do echo -e "\nListing Instances for profile $profile in region: '$region'..." aws ec2 describe-instances \ --filters "Name=instance-state-name,Values=running" \ --query 'Reservations[*].Instances[*].[InstanceId, PublicIpAddress, LaunchTime, InstanceType, Tags[?Key==`Name`] | [0].Value]| sort_by(@, &@[0][2])' \ --region $region \ --profile $profile \ --output table done done cat <<EOT </pre> </body> </html> EOT ) | /usr/sbin/sendmail -t |
1 2 3 4 |
my $created_at = '2017-09-18T13:43:40Z'; my $marker = DateCalc('today','30 days ago'); my $cmp = Date_Cmp($created_at,$marker); if ($cmp < 0) { print "Older than marker!\n"; } else { print "Same date or later than marker\n"; } |
For a quick visual check to see what the human-readable date is based on a UNIX timestamp integer: php -r ‘print date(“r”,1483228799);’ php -r ‘print strtotime(“1 Jan 2015”) – 1;’
1 2 3 4 5 6 7 8 9 10 11 |
$now = time(); $this_year = strtotime('1 July'); $delta = $this_year - $now; if ($delta > 0) { // this year's anniversary date is still to come, use it $anniversary = $this_year; } else { // nope, use next year's date $anniversary = strtotime('1 July +1 year'); } |
$lastDay = date(“Y-m-t”, strtotime(“-3 months”)); $firstDay = date(“Y-m-01”, strtotime(“-3 months”));
1 2 3 4 5 |
date_default_timezone_set('America/New_York'); $datetime1 = new DateTime('2009-10-31'); $datetime2 = new DateTime('now'); $interval = $datetime1->diff($datetime2); print $interval->format('%a days_elapsed'); |
http://www.php.net/manual/en/datetime.diff.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use Date::Manip; my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my $month = $months[ (localtime)[4] ]; my $last = &UnixDate("last saturday in $month", "%B %e"); $last .= &gensuffix($last); sub gensuffix { my($val) = @_; my $end_num = substr($val, -1, 1); my $suffix = 'th'; $suffix = 'st' if $end_num == 1; $suffix = 'nd' if $end_num == 2; $suffix = 'rd' if $end_num == 3; return $suffix; } |
Click HERE for the original post.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// remember the old function var _gotoToday = jQuery.datepicker._gotoToday; // datepicker is directly inside the jQuery object, so override that jQuery.datepicker._gotoToday = function(a){ var target = jQuery(a); var inst = this._getInst(target[0]); // call the old function, so default behaviour is kept _gotoToday.call(this, a); // now do an additional call to _selectDate which will set the date and close // close the datepicker (if it is not inline) jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear)); } |
Extremely simple way to set the date and time the same as another server: (Requires SSH access to the server that has the time you want to copy; does NOT have to be root access) [code]root@host# date ssh user@timehost date "+%Y%m%d%H%M.%S"[/code]