Discuz!开发之时间处理函数dgmdate()详解
\source\function\function_core.php
相关代码:
/**
* 格式化时间
* @param $timestamp - 时间戳
* @param $format - dt=日期时间 d=日期 t=时间 u=个性化 其他=自定义
* @param $timeoffset - 时区
* @return string
*/
function dgmdate($timestamp, $format = 'dt', $timeoffset = '9999', $uformat = '') {
global $_G;
$format == 'u' && !$_G['setting']['dateconvert'] && $format = 'dt';
static $dformat, $tformat, $dtformat, $offset, $lang;
if($dformat === null) {
$dformat = getglobal('setting/dateformat');
$tformat = getglobal('setting/timeformat');
$dtformat = $dformat.' '.$tformat;
$offset = getglobal('member/timeoffset');
$sysoffset = getglobal('setting/timeoffset');
$offset = $offset == 9999 ? ($sysoffset ? $sysoffset : 0) : $offset;
$lang = lang('core', 'date');
}
$timeoffset = $timeoffset == 9999 ? $offset : $timeoffset;
$timestamp += $timeoffset * 3600;
$format = empty($format) || $format == 'dt' ? $dtformat : ($format == 'd' ? $dformat : ($format == 't' ? $tformat : $format));
if($format == 'u') {
$todaytimestamp = TIMESTAMP - (TIMESTAMP + $timeoffset * 3600) % 86400 + $timeoffset * 3600;
$s = gmdate(!$uformat ? $dtformat : $uformat, $timestamp);
$time = TIMESTAMP + $timeoffset * 3600 - $timestamp;
if($timestamp >= $todaytimestamp) {
if($time > 3600) {
$return = intval($time / 3600).' '.$lang['hour'].$lang['before'];
} elseif($time > 1800) {
$return = $lang['half'].$lang['hour'].$lang['before'];
} elseif($time > 60) {
$return = intval($time / 60).' '.$lang['min'].$lang['before'];
} elseif($time > 0) {
$return = $time.' '.$lang['sec'].$lang['before'];
} elseif($time == 0) {
$return = $lang['now'];
} else {
$return = $s;
}
if($time >=0 && !defined('IN_MOBILE')) {
$return = '<span title="'.$s.'">'.$return.'</span>';
}
} elseif(($days = intval(($todaytimestamp - $timestamp) / 86400)) >= 0 && $days < 7) {
if($days == 0) {
$return = $lang['yday'].' '.gmdate($tformat, $timestamp);
} elseif($days == 1) {
$return = $lang['byday'].' '.gmdate($tformat, $timestamp);
} else {
$return = ($days + 1).' '.$lang['day'].$lang['before'];
}
if(!defined('IN_MOBILE')) {
$return = '<span title="'.$s.'">'.$return.'</span>';
}
} else {
$return = $s;
}
return $return;
} else {
return gmdate($format, $timestamp);
}
}
Discuz!开发之时间处理函数dgmdate()详解的更多相关文章
- python开发笔记之zip()函数用法详解
今天分享一篇关于python下的zip()函数用法. zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素按顺序组合成一个tuple,每个tuple中包含的是原 ...
- PHP用strtotime()函数比较两个时间的大小实例详解
在PHP开发中,我们经常会对两个时间的大小进行判断,但是,在PHP中,两个时间是不可以直接进行比较,因为时间是由年.月.日.时.分.秒组成的,所以,如果需要将两个时间进行比较的话,我们首先要做的就是将 ...
- SQL Server数据库ROW_NUMBER()函数使用详解
SQL Server数据库ROW_NUMBER()函数使用详解 摘自:http://database.51cto.com/art/201108/283399.htm SQL Server数据库ROW_ ...
- PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明
PHP函数篇详解十进制.二进制.八进制和十六进制转换函数说明 作者: 字体:[增加 减小] 类型:转载 中文字符编码研究系列第一期,PHP函数篇详解十进制.二进制.八进制和十六进制互相转换函数说明 ...
- PHP date函数参数详解
PHP date函数参数详解 作者: 字体:[增加 减小] 类型:转载 time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计 ...
- SQL中CONVERT()函数用法详解
SQL中CONVERT函数格式: CONVERT(data_type,expression[,style]) 参数说明: expression 是任何有效的 Microsoft® SQL Server ...
- SQL Server日期时间格式转换字符串详解
本文我们主要介绍了SQL Server日期时间格式转换字符串的相关知识,并给出了大量实例对其各个参数进行对比说明,希望能够对您有所帮助. 在SQL Server数据库中,SQL Server日期时间格 ...
- php中setcookie函数用法详解(转)
php中setcookie函数用法详解: php手册中对setcookie函数讲解的不是很清楚,下面是我做的一些整理,欢迎提出意见. 语法: bool set ...
- Python学习入门教程,字符串函数扩充详解
因有用户反映,在基础文章对字符串函数的讲解太过少,故写一篇文章详细讲解一下常用字符串函数.本文章是对:程序员带你十天快速入门Python,玩转电脑软件开发(三)中字符串函数的详解与扩充. 如果您想学习 ...
随机推荐
- [LeetCode] 255. Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- 用Autofac替换.net core 内置容器
官方建议使用内置容器,但有些功能并不支持,如下: 属性注入 基于名称的注入 子容器 自定义生存期管理 Func<T> 支持 所以可以使用其他第三方IOC容器,如Autofac,下面为学习使 ...
- 使用nodemon提高nodejs调试效率
1.安装 nodemon 直接用npm安装既可,键入命令: npm -g install nodemon .如果不行,检查电脑有没有联网,联网后输入 sudo npm -g install nodem ...
- Flask高级
关于Flask启动,和请求处理 #关于后端服务的启动,无非就是启动实现了WSGI协议的socket #关于flask启动的无非就是下面两段代码 #加载配置,创建Flask对象 app = Flask( ...
- [转帖]编写shell脚本所需的语法和示例
编写shell脚本所需的语法和示例 https://blog.csdn.net/CSDN___LYY/article/details/100584638 在说什么是shell脚本之前,先说说什么是sh ...
- 图解微信小程序---实现行的删除和增加操作
图解微信小程序之实现行的删除和增加操作 代码笔记部分 第一步:在项目的app.json中创建一个新的页面(页面名称英文,可自定义) 第二步:在创建的新页面中编写页面(注意bindtap属性值,因为是我 ...
- [转] Nginx配置中的location、root、alias
Nginx配置中的location.root.alias location & root 初始配置 [root@adailinux vhost]# cat rio.conf server { ...
- 学习Linq之前必须知道的几种语法糖
» 引用百度解释: 语法糖(Syntactic sugar),也译为糖衣语法,是由英国计算机科学家彼得·约翰·兰达(Peter J. Landin)发明的一个术语,指计算机语言中添加的某种语 ...
- swagger 集成后发布到服务器报错[Could not find file 'D:\\home\\site\\wwwroot\\bin\\WebAPI.XML]
webapi集成swagger后,在本地运行没有问题,但是发布到服务器上就有问题. 报错信息:Could not find file 'D:\\home\\site\\wwwroot\\bin\\We ...
- mvc控制器接收ajax传送的数据
视图层中ajax传数据 $.ajax({ type: "post",//提交方式 data: { complay_arry: complay_arry, site_arry: si ...