Ejemplo n.º 1
0
/**
 * Get the date
 *
 * Example)
 * <code>
 * get_date('D, d M Y H:i:s T', get_filetime($_page))
 * </code>
 *
 * @param string $format date format
 * @param int timestamp or current UTIME if not specified
 * @uses get_zontime_offset
 */
function get_date($format, $timestamp = NULL)
{
    $esc = '';
    $i = strlen(ZONE) - 1;
    for ($j = 0; $j < $i; $j++) {
        $esc .= '\\';
    }
    $format = preg_replace('/(?<!' . $esc . ')T/', preg_replace('/(.)/', $esc . '$1', ZONE), $format);
    //$format = preg_replace('/(?<!\\\)T/',
    //	preg_replace('/(.)/', '\\\$1', ZONE), $format);
    $time = ZONETIME + ($timestamp !== NULL ? $timestamp : UTIME);
    $str = gmdate($format, $time);
    if (ZONETIME == 0) {
        return $str;
    }
    $zonetime = get_zonetime_offset(ZONETIME);
    return str_replace('+0000', $zonetime, $str);
}
Ejemplo n.º 2
0
function get_date($format, $timestamp = NULL)
{
    /*
     * $format で指定される T を ZONE で置換したいが、
     * date 関数での書式指定文字となってしまう可能性を回避するための事前処理
     */
    $l = strlen(ZONE);
    $zone = '';
    for ($i = 0; $i < $l; $i++) {
        $zone .= '\\' . substr(ZONE, $i, 1);
    }
    $format = str_replace('\\T', '$$$', $format);
    // \T の置換は除く
    $format = str_replace('T', $zone, $format);
    $format = str_replace('$$$', '\\T', $format);
    // \T に戻す
    $time = ZONETIME + ($timestamp !== NULL ? $timestamp : UTIME);
    $str = gmdate($format, $time);
    if (ZONETIME == 0) {
        return $str;
    }
    $zonetime = get_zonetime_offset(ZONETIME);
    return str_replace('+0000', $zonetime, $str);
}