php 1970以前,php 1970年前日期问题

function smarty_make_timestamp($string)

{

if(empty($string)) {

// use "now":

$time = time();

} elseif (preg_match('/^\d{14}$/', $string)) {

// it is mysql timestamp format of YYYYMMDDHHMMSS?

$time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),

substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));

} elseif (is_numeric($string)) {

// it is a numeric string, we handle it as timestamp

$time = (int)$string;

} else {

// strtotime should handle it

$time = strtotime($string);

if ($time == -1 || $time === false) {

// strtotime() was not able to parse $string, use "now":

$time = time();

}

}

return $time;

}

function smarty_modifier_date_format($string, $format = '%Y-%m-%d %H:%M:%S ', $default_date = '')

{

if ($string != '') {

$timestamp = smarty_make_timestamp($string);

} elseif ($default_date != '') {

$timestamp = smarty_make_timestamp($default_date);

} else {

return;

}

if (DIRECTORY_SEPARATOR == '\\') {

$_win_from = array('%D',       '%h', '%n', '%r',          '%R',    '%t', '%T');

$_win_to   = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');

if (strpos($format, '%e') !== false) {

$_win_from[] = '%e';

$_win_to[]   = sprintf('%\' 2d', date('j', $timestamp));

}

if (strpos($format, '%l') !== false) {

$_win_from[] = '%l';

$_win_to[]   = sprintf('%\' 2d', date('h', $timestamp));

}

$format = str_replace($_win_from, $_win_to, $format);

}

return strftime($format, $timestamp);

}

$sd1 = strtotime("1802-10-12");

echo $sd1.'|| ';

$sd = smarty_make_timestamp("1905-10-12");

echo $sd.'|| ';

echo date("Y-m-d",$sd).'|| ';

echo smarty_modifier_date_format($sd);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值