Question:
I have working code which returns all the files under s3 bucket. I have to get today’s uploaded files for further processing.
Code to get files :
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 |
use Aws\S3\S3Client; $s3Client = S3Client::factory(array( 'region' => 'us-east-1', 'version' => '2006-03-01', 'credentials' => array( 'key' => 'XXXX', 'secret' => 'YYYYYYYY' ) )); $iterator = $s3Client->getIterator('ListObjects', array( 'Bucket' => 'mybucket', 'Prefix' => 'adityamusic', 'Suffix' => '.xlsx', ), array( 'limit' => 999, 'page_size' => 100 )); foreach ($iterator as $object) { print_r($object['LastModified']); print_r($object['LastModified']['date']); //this gives error } |
print_r($object['LastModified'])
outputs as :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Array ( [Key] => mymusic/ [LastModified] => Aws\Api\DateTimeResult Object ( [date] => 2016-08-03 06:20:31 [timezone_type] => 2 [timezone] => Z ) [ETag] => "sadfasdf2342" [Size] => 0 [StorageClass] => STANDARD [Owner] => Array ( [DisplayName] => test [ID] => asdfasdfasdf ) ) |
I am not able to access date key.
Answer:
LastModified
is an instance of Aws\Api\DateTimeResult
class, since DateTimeResult
extends \DateTime
object, just use format
method as you would normally do when working with standard DateTime objects.
echo $object['LastModified']->format(\DateTime::ISO8601)
Read here for more formatting options.
P.S. $object['LastModified']->date
will not work because its not designed to be accessed directly.