当前位置: 首页>>代码示例>>PHP>>正文


PHP iso8601_timezone_to_offset函数代码示例

本文整理汇总了PHP中iso8601_timezone_to_offset函数的典型用法代码示例。如果您正苦于以下问题:PHP iso8601_timezone_to_offset函数的具体用法?PHP iso8601_timezone_to_offset怎么用?PHP iso8601_timezone_to_offset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了iso8601_timezone_to_offset函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: iso8601_to_datetime

/**
 * Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt].
 *
 * @since 1.5.0
 *
 * @param string $date_string Date and time in ISO 8601 format {@link http://en.wikipedia.org/wiki/ISO_8601}.
 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'.
 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s.
 */
function iso8601_to_datetime($date_string, $timezone = 'user')
{
    $timezone = strtolower($timezone);
    if ($timezone == 'gmt') {
        preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\\+|\\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);
        if (!empty($date_bits[7])) {
            // we have a timezone, so let's compute an offset
            $offset = iso8601_timezone_to_offset($date_bits[7]);
        } else {
            // we don't have a timezone, so we assume user local timezone (not server's!)
            $offset = HOUR_IN_SECONDS * get_option('gmt_offset');
        }
        $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
        $timestamp -= $offset;
        return gmdate('Y-m-d H:i:s', $timestamp);
    } else {
        if ($timezone == 'user') {
            return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\\+|\\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);
        }
    }
}
开发者ID:pauEscarcia,项目名称:AIMM,代码行数:30,代码来源:formatting.php

示例2: convert_date

 function convert_date($date)
 {
     preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\\.[0-9]+)?(Z|[\\+|\\-][0-9]{2,4}){0,1}#', $date, $date_bits);
     $offset = iso8601_timezone_to_offset($date_bits[7]);
     $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
     $timestamp -= $offset;
     // Convert from Blogger local time to GMT
     $timestamp += get_option('gmt_offset') * 3600;
     // Convert from GMT to WP local time
     return gmdate('Y-m-d H:i:s', $timestamp);
 }
开发者ID:pravinhirmukhe,项目名称:flow1,代码行数:11,代码来源:blogger.php


注:本文中的iso8601_timezone_to_offset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。