How do you get a current datetime

Following meringue philosophy, it’s a piece of cake. Just ask the following question: what do I need? You need a current datetime, that is, now. Here goes the object – $currentDatetime = new Now();.

You can work with this datetime further: you can get datetimes in the future or in the past, or format it to your taste.

Often times, you want to know what time it is in some other timezone. For example, it’s 15:08 in Moscow, and you want to know what time it is in Central Europe. In other words, you want to know specific point in time adjusted according to some other timezone, in our case it could be Berlin, Paris or Rome. Hence the class: AdjustedAccordingToTimeZone. So here is how you can convert a datetime to another timezone:

(new AdjustedAccordingToTimeZone(
    new FromISO8601('2018-04-25 15:08:01+03:00'),
    new CET()
))
    ->value()

Currently there are a few of built-in meringue timezones, feel free to add yours.