1

In Craft 2 I've used createFromString() as following:

DateTime::createFromString($pubDate, craft()->timezone)

But if I use this function in craft cms 3 then I'm getting the following error:

Call to undefined method DateTime::createFromString()

Is there any alternative way to use the createFromString() in Craft 3?

2

You're looking for the toDateTime() method in the DateTimeHelper class:

DateTimeHelper::toDateTime($pubDate, true);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.