您的位置:首页 > Web前端 > JavaScript

将字符串或日期转换成年月日的格式,js方法

2014-07-04 10:23 751 查看
<!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=gb2312" />
<title>无标题文档</title>
<script language=Javascript>
function time(){
//获得显示时间的div
t_div = document.getElementById('showtime');

<span style="font-family:Microsoft YaHei;font-size:12px;color:#ff0000;"><strong>var now="2014-05-18";
//或者var now = new Date();  </strong></span>

//替换div内容
t_div.innerHTML = "现在是"+<span style="font-family:Microsoft YaHei;color:#ff0000;"><strong>now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日";</strong></span>

//等待一秒钟后调用time方法,由于settimeout在time方法内,所以可以无限调用
setTimeout(time,1000);

}
</script>
</head>

<body  onload="time()">
<div id="showtime"></div>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息