brick / date-time

Date and time library for PHP
MIT License
323 stars 29 forks source link

Retrieving Instant from ISO DateTime string #14

Closed jakeworrall closed 5 years ago

jakeworrall commented 5 years ago

Hi,

I am trying to retrieve an instant from an ISO datetime string, eg "2019-05-10T11:00:00Z".

I have found a way to do this using the IsoParsers::offsetDateTime() parser but it seems a bit longwinded:

$parseResult = IsoParsers::offsetDateTime()->parse($dateTimeString);
$instant = ZonedDateTime::from($parseResult)->getInstant();

Is this the best way to do this?

Thanks, Jake

BenMorel commented 5 years ago

Hi Jake, yes there is 👍

$instant = ZonedDateTime::parse('2019-05-10T11:00:00Z')->getInstant();