在PHP中创建此日期格式:YYYY-MM-DDTHH:MM:SS + -HH:MM [英] Creating this date format in PHP: YYYY-MM-DDTHH:MM:SS+-HH:MM

查看:777
本文介绍了在PHP中创建此日期格式:YYYY-MM-DDTHH:MM:SS + -HH:MM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SparkPost API,但无法理解如何在PHP中使用YYYY-MM-DDTHH:MM:SS + -HH:MM创建日期。

I'm working with the SparkPost API and I am having trouble understanding how to create a date with YYYY-MM-DDTHH:MM:SS+-HH:MM in PHP.

+-HH:MM是什么时区?

What is +-HH:MM, is that the timezone?

回顾其他类似的堆栈交换主题,我得到的最接近的是:

The closest I have come from reviewing other similar stack exchange topics is this:

if ( !$send_now && self::$row->datetime )
{
   // This data is available: [send_datetime] => 04/01/2016 01:30
   // This data is available: [timezone] => MDT-UTC-7
   $send_at = date( 'Y-m-dTH:i:s' , strtotime( self::$row->datetime ) );
}
else
{
   $send_at = 'now';
}

另一个供我参考的是我正在使用WordPress,并且希望定位时区实例设置为。

Another FYI is I am working with WordPress and will want to target the time zone the instance is set to.

任何帮助表示赞赏。

if ( !$send_now && self::$row->datetime ) {
    $send_at = date( 'c' , strtotime( self::$row->datetime ) );
    if (isset(self::$email_settings['timezone'])) {
        $date_parts = explode('+' , $send_at );
        $timezone_parts = explode('UTC' , self::$email_settings['timezone'] );
        $send_at = $date_parts[0] .$timezone_parts[1].':00';
    }
} else {
        $send_at = 'now';
}


推荐答案

这是ISO 8601日期格式。请参见 https://en.wikipedia.org/wiki/ISO_8601

This is an ISO 8601 date format. See https://en.wikipedia.org/wiki/ISO_8601.

+-HH:MM是与UTC的时区偏移量。

The +-HH:MM is the timezone offset from UTC.

在PHP中,您可以使用'c'将日期格式设置为ISO 8601。

In PHP you can use 'c' to format a date as ISO 8601.

$send_at = date( 'c', strtotime( self::$row->datetime ) );

这篇关于在PHP中创建此日期格式:YYYY-MM-DDTHH:MM:SS + -HH:MM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆