天空小小岛技术网站
标题:
unix时间戳与时间互转工具源码
[打印本页]
作者:
一粒米
时间:
2010-5-26 18:01
标题:
unix时间戳与时间互转工具源码
<?php
/*
时间互换
Author: Arice
Site: http://www.tkxxd.net
*/
//note 设置时区
$timeoffset = 8;
if(PHP_VERSION > '5.1') {
@date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));
}
//note 取得当前时间戳
$timestamp = time();
$now = gmdate('Y-m-d H:i:s', $timestamp + $timeoffset * 3600);
if(isset($_POST['t'])) {
$t = trim($_POST['t']);
} else {
$t = '';
}
if($t) {
//note 判断是否时间戳
if(preg_match('/^\d+$/', $t)) {
$r = gmdate('Y-m-d H:i:s', $t + $timeoffset * 3600);
} else {
$r = strtotime($t);
}
$result = '结果: '.$r;
} else {
$result = '';
}
echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>时间转换工具 - Powered by tkxxd</title>
<meta name="keywords" content="时间戳与时间互转" />
<meta name="description" content="时间戳与时间互转,天空小小岛,www.tkxxd.net" />
<meta name="generator" content="Discuz! 7.0.0" />
<meta name="author" content="TKXXD" />
<meta name="copyright" content="2004-2015" />
<meta name="MSSmartTagsPreventParsing" content="True" />
<meta http-equiv="MSThemeCompatible" content="Yes" />
</head>
<body>
<form method="post" name="form1" action="?">
当前时间: $now 时间戳: $timestamp<br /><br />
输入时间或时间戳: <input type="text" name="t" value="$t">
<input type="submit" name="submit" value="提交"><br />
</form>
$result
</body>
</html>
EOT;
?>
复制代码
预览:
http://www.tkxxd.net/time.php
欢迎光临 天空小小岛技术网站 (http://tkxxd.net/)
Powered by Discuz! X3.1