设计一个php动态网页,根据输入的年月日,计算出星期。

设计一个php动态网页,其中3个文本框,在文本框中分别输入年月日,根据输入的年月日,自动计算出年龄和星期。如图所示:

<!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=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
请输入您的出生日期
<input type="text" name="year" id="textfield" value="<?=isset($_POST['year'])?$_POST['year']:""?>"/>

<input type="text" name="mon" id="textfield2" value="<?=isset($_POST['mon'])?$_POST['mon']:""?>"/>

<input type="text" name="mday" id="textfield3" value="<?=isset($_POST['mday'])?$_POST['mday']:""?>"/>

<input type="submit" name="button" id="button" value="提交" />
</form>
<?
if(isset($_POST['button'])){
$dateold = ($_POST['year']."-".$_POST['mon']."-".$_POST['mday']);
$date = date("Y-m-d") ;
$age = $date-$dateold;

$d=date ("l", mktime (0,0,0,$_POST['mon'],$_POST['mday'],$_POST['year']));
echo "<br>";
echo "您的年龄为:{$age}<br>";
echo "出生时是一周的:{$d}";
}
?>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-30
mktime (0,0,0,12,32,1997)); 月 日 年 转化为时间戳
echo date ("D", mktime (0,0,0,12,32,1997));
直接输出星期几,如 Fri
生日 用当前时间减去这个时间就得到啦