• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

unix timestamp

AWS display Lightsail snapshots

December 1, 2021

How to display Lightsail snapshots.

#!/bin/bash
displaysnapshots () {
  echo '--------------------------------------------------------'
  aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name]' --output text | sort
  echo '--------------------------------------------------------'
}
displaysnapshots

#!/bin/bash displaysnapshots () { echo '--------------------------------------------------------' aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name]' --output text | sort echo '--------------------------------------------------------' } displaysnapshots

Result.

daily_ulyme_1637812801
daily_ulyme_1637899201
daily_ulyme_1637985601
daily_ulyme_1638072001

daily_ulyme_1637812801 daily_ulyme_1637899201 daily_ulyme_1637985601 daily_ulyme_1638072001

Adding timestamp to the output.

  aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name,createdAt]' --output text | sort

aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name,createdAt]' --output text | sort

Result.

daily_ulyme_1637812801	1637812806.853
daily_ulyme_1637899201	1637899208.285
daily_ulyme_1637985601	1637985606.184
daily_ulyme_1638072001	1638072006.579

daily_ulyme_1637812801 1637812806.853 daily_ulyme_1637899201 1637899208.285 daily_ulyme_1637985601 1637985606.184 daily_ulyme_1638072001 1638072006.579

Convert Unix timestamp to iso8601. Edit your ~/.aws/config file. Add this line.

cli_timestamp_format = iso8601

cli_timestamp_format = iso8601

Result.

daily_ulyme_1637812801	2021-11-25T04:00:06.853000+00:00
daily_ulyme_1637899201	2021-11-26T04:00:08.285000+00:00
daily_ulyme_1637985601	2021-11-27T04:00:06.184000+00:00
daily_ulyme_1638072001	2021-11-28T04:00:06.579000+00:00

daily_ulyme_1637812801 2021-11-25T04:00:06.853000+00:00 daily_ulyme_1637899201 2021-11-26T04:00:08.285000+00:00 daily_ulyme_1637985601 2021-11-27T04:00:06.184000+00:00 daily_ulyme_1638072001 2021-11-28T04:00:06.579000+00:00

Filed Under: Cloud Tagged With: aws, convert, lightsail, list, snapshots, timestamp, unix timestamp

Comparing Time

May 9, 2017

Here’s a neat little PHP script that compares a set date/time to the current time. The time() function sets the $now variable to the current Unix timestamp. The strtotime() function converts a date string to a Unix timestamp. The result is assigned to the $setdate variable. The two variables containing Unix timestamps are then compared. A simple if-then statement determines if the date is in the past or future.

date_default_timezone_set('America/Los_Angeles');
$setdate = strtotime("May 9, 2017 12:27PM");
$now = time();
if ( $setdate > $now ) : echo 'Future date'; else : echo 'Past date'; endif;

date_default_timezone_set('America/Los_Angeles'); $setdate = strtotime("May 9, 2017 12:27PM"); $now = time(); if ( $setdate > $now ) : echo 'Future date'; else : echo 'Past date'; endif;

You may have to change the default timezone if your server is in a different timezone.

Filed Under: PHP Tagged With: comparison, date, time, unix timestamp

  • Home
  • About
  • Archives

Copyright © 2023