Moment.php

Wrapper for PHP's DateTime class inspired by moment.js

1. DateTime from "Now" (UTC)

{{test01}}

2. Set date and add 2 hours

Date: 15.05.2012 12:30:00 (CET)

{{test02}}

3. Set date and subtract 7 days and 15 minutes

Date: 15.05.2012 12:30:00 (CET)

{{test03}}

4. Difference between two dates

Date#1: 12.05.2012 / 15:00:00 (UTC)

Date#2: 25.09.2011 / 10:00:00 (UTC)

Difference seconds: {{test04.01}}

Difference in minutes: {{test04.02}}

Difference in hours: {{test04.03}}

Difference in days: {{test04.04}}

Difference in weeks: {{test04.05}}

Difference in months: {{test04.06}}

Difference in years: {{test04.07}}

Difference relative: {{test04.08}}

5. Difference Date#1 to "Now"

Date#1: {{test05.00}}

Difference seconds: {{test05.01}}

Difference in minutes: {{test05.02}}

Difference in hours: {{test05.03}}

Difference in days: {{test05.04}}

Difference in weeks: {{test05.05}}

Difference in months: {{test05.06}}

Difference in years: {{test05.07}}

Difference relative: {{test05.08}}

6. CET to UTC

CET: {{test06.01}}

UTC: {{test06.02}}

7. Custom format

{{test07.00}}

Default locale (L): {{test07.01}}

{{test07.locale}} locale (LT): {{test07.02}}

{{test07.locale}} locale (L): {{test07.03}}

{{test07.locale}} locale (l): {{test07.04}}

{{test07.locale}} locale (LL): {{test07.05}}

{{test07.locale}} locale (ll): {{test07.06}}

{{test07.locale}} locale (LLL): {{test07.07}}

{{test07.locale}} locale (lll): {{test07.08}}

{{test07.locale}} locale (LLLL): {{test07.09}}

{{test07.locale}} locale (llll): {{test07.10}}

8. Get period

Reference date for calculating period: {{test08.00}}

Weekly period:
Monthly period:
Quarter period:

9. Use other format definitions via FormatsInterface

Reference date '2012-04-25T03:00:00' in 'CET'.

Moment.php format:
"l, F jS Y g:i A"
{{test09.01}}

Moment.js
"LLLL"
{{test09.02}}

Moment.php format: (with fixed ordinal representation)
"WS [week of the year]"
{{test09.03}}

Moment.js
"WO"
{{test09.04}}

10. Calendar Time

Calendar time displays time relative to now, but slightly differently than moment::fromNow.

moment::calendar will format a date with different strings depending on how close to today the date is.

Last week
{{test10.01}}

The day before
{{test10.02}}

The same day
{{test10.03}}

The next day
{{test10.04}}

Upcoming days
{{test10.05}}

Everything else
{{test10.06}}

11. startOf()

Reference date {{test11.00}}

12. endOf()

Reference date {{test12.00}}