brick / date-time

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

Parse from String with custom Pattern #30

Open hantsy opened 3 years ago

hantsy commented 3 years ago

In Java 8 DateTime, the parse can accept a custom Pattern simply.

LocalDateTime.parse(fields[1].trim(), DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")),
jurchiks commented 2 years ago

That's just https://www.php.net/manual/en/datetime.createfromformat.php

hantsy commented 2 years ago

That's just https://www.php.net/manual/en/datetime.createfromformat.php

Currently I used the following statement to parse a string to LocalDateTime, it looks a little tedious. Hope there is a method aligned to Java DateTime.

LocalDateTime::fromDateTime(DateTime::createFromFormat('d/m/Y H:i:s', $fromDate))
solodkiy commented 2 years ago

Relates to https://github.com/brick/date-time/issues/3