如何将我的时间从2010-12-30 23:21:46
ISO 8601 日期格式转换?(-_-;)
问问题
152539 次
7 回答
258
面向对象
这是推荐的方式。
$datetime = new DateTime('2010-12-30 23:21:46');
echo $datetime->format(DateTime::ATOM); // Updated ISO8601
程序
对于较旧版本的 PHP,或者如果您更喜欢程序代码。
echo date(DATE_ISO8601, strtotime('2010-12-30 23:21:46'));
于 2011-03-16T07:42:14.267 回答
5
如何从 ISO 8601 转换为 unixtimestamp :
strtotime('2012-01-18T11:45:00+01:00');
// Output : 1326883500
如何从 unixtimestamp 转换为 ISO 8601(时区服务器):
date_format(date_timestamp_set(new DateTime(), 1326883500), 'c');
// Output : 2012-01-18T11:45:00+01:00
如何从 unixtimestamp 转换为 ISO 8601 (GMT):
date_format(date_create('@'. 1326883500), 'c') . "\n";
// Output : 2012-01-18T10:45:00+00:00
如何从 unixtimestamp 转换为 ISO 8601(自定义时区):
date_format(date_timestamp_set(new DateTime(), 1326883500)->setTimezone(new DateTimeZone('America/New_York')), 'c');
// Output : 2012-01-18T05:45:00-05:00
于 2017-04-03T18:32:15.427 回答
3
如果您尝试在 datetime-local 中设置一个值
date("Y-m-d\TH:i",strtotime('2010-12-30 23:21:46'));
//output : 2010-12-30T23:21
于 2017-11-13T17:23:03.097 回答
0
你可以这样试试:
$datetime = new DateTime('2010-12-30 23:21:46');
echo $datetime->format(DATE_ATOM);
于 2020-09-03T10:50:09.647 回答
0
ISO 8601 在 PHP 中基本上表示为"Y-m-d\TH:i:sP"
您可以从常量中获取此值:
DateTime::ATOM
- 对于低于 7.2 的 PHP 版本(已删除)
DateTimeInterface::ATOM
- 自 7.2 以来的 PHP 版本
于 2021-08-04T13:16:11.113 回答
0
根据PHP 官方文档,您可以简单地将其格式化为:
echo $objDateTime->format('c'); // ISO8601 formated datetime
echo $objDateTime->format(DateTime::ISO8601); // Another way to get an ISO8601 formatted string
于 2021-10-07T14:00:05.890 回答