Shorthand HTML5 datetime-local-friendly 日期格式(无时区)?

Shorthand for HTML5 datetime-local-friendly date format (no timezone)?

有没有快速格式化 \DateTime into HTML-friendly Local date and time string(例如 1986-01-28T11:38:00.01)的方法?

两者都DATE_W3C and c will produce a timezone, which doesn't work with datetime-local

我知道我可以做到 "Y-m-d\TH:i:s",但很好奇现在是否有更优雅的 shorthand?

您可以使用 DateTimeInterface 上定义的常量之一:

const ATOM = 'Y-m-d\TH:i:sP';
const COOKIE = 'l, d-M-Y H:i:s T';
const ISO8601 = 'Y-m-d\TH:i:sO';
const RFC822 = 'D, d M y H:i:s O';
const RFC850 = 'l, d-M-y H:i:s T';
const RFC1036 = 'D, d M y H:i:s O';
const RFC1123 = 'D, d M Y H:i:s O';
const RFC2822 = 'D, d M Y H:i:s O';
const RFC3339 = 'Y-m-d\TH:i:sP';
const RFC3339_EXTENDED = 'Y-m-d\TH:i:s.vP';
const RFC7231 = 'D, d M Y H:i:s \G\M\T';
const RSS = 'D, d M Y H:i:s O';
const W3C = 'Y-m-d\TH:i:sP';

示例:

(new \DateTime)->format(\DateTimeInterface::W3C)