简体   繁体   English

使用PHP更改ISO 8601日期格式

[英]Change the ISO 8601 date format using PHP

I am trying to get the current date/time using Data Type: ISODateTime and Format: YYYY-MM-DDTHH:MM:SS eg 2012-02-06T08:35:30. 我正在尝试使用数据类型:ISODateTime和格式:YYYY-MM-DDTHH:MM:SS来获取当前日期/时间,例如2012-02-06T08:35:30。 I searched how I would do this in PHP and found that I can use; 我搜索了如何在PHP中执行此操作,并发现可以使用。

$formatedDate = date("c");

Although the output of this is almost correct is not quite what I need and I can't figure out how to alter it, the current output of this is; 尽管此输出几乎是正确的,但并不是我所需要的,我也不知道如何更改它,但当前的输出是:

2014-07-01T10:53:10+02:00 2014-07-01T10:53:10 + 02:00

My problem is I need to remove the "+02:00" and also this time is an hour ahead of my local time, which is what I need. 我的问题是我需要删除“ +02:00”,而且这个时间比我的本地时间早一个小时,这是我所需要的。 Therefore, in this example, I would require; 因此,在这个例子中,我会要求;

2014-07-01T09:53:10 2014-07-01T09:53:10

Any help would be really appreciated. 任何帮助将非常感激。 Thanks. 谢谢。

You could just format the date manually. 您可以手动设置日期格式。

$formattedDate =  date('Y-m-d\TH:i:s');

To get your local time, use date_default_timezone_set() to set the appropriate timezone (before declaring $formattedDate ). 要获取您的本地时间,请使用date_default_timezone_set()设置适当的时区(在声明$formattedDate之前)。

// Change 'America/New_York' to your timezone
date_default_timezone_set('America/New_York');

See demo 观看演示


To find your timezone, see the List of Supported Timezones . 要查找您的时区,请参阅支持的时区列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM