convert_date_to_iso8601 ( $datestamp )

Checks to see if a date stamp is ISO-8601 formatted, and if not, makes it so.

Access

public

Parameters

Parameter

Type

Required

Description

$datestamp

string

Required

A date stamp, or a string that can be parsed into a date stamp.

Returns

Type

Description

string

An ISO-8601 formatted date stamp.

Examples

Convert a date into ISO-8601 format.

// Instantiate the object
$s3 = new AmazonS3();

// Test for ISO-8601, and convert if not.
$date_correct = '2009-08-01T07:00:00Z';
$date_incorrect = '1 August 2009, 7am GMT';

// Success?
var_dump($s3->util->convert_date_to_iso8601($date_correct));
var_dump($s3->util->convert_date_to_iso8601($date_incorrect));
Result:
string(20) "2009-08-01T07:00:00Z"
string(20) "2009-08-01T07:00:00Z"

Source

Method defined in utilities/utilities.class.php | Toggle source view (9 lines) | View on GitHub

public function convert_date_to_iso8601($datestamp)
{
    if (!preg_match('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}((\+|-)\d{2}:\d{2}|Z)/m', $datestamp))
    {
        return gmdate(self::DATE_FORMAT_ISO8601, strtotime($datestamp));
    }

    return $datestamp;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback