代码如下:
代码如下 |
复制代码 |
function strToDate(str, ext) {
if (str == null || str == '') return;
var arys = new Array();
arys = str.split('-');
var newDate = new Date(arys[0], arys[1] - 1, arys[2], 9, 0, 0);
if (ext) {
newDate = new Date(newDate.getTime() + 1000 * 60 * 60 * 24);
}
return newDate;
}
function showit(str, start, end) {
var date = new Date();
var start = strToDate(start);
var end = strToDate(end, false);
if (date & gt; start & amp; & amp; date document.write(str);
}
}
调取:
showit('Your ads','2011-07-06','2011-07-18');
|
例2
代码如下 |
复制代码 |
<script type="text/javascript">
function strToDate(str, ext) {
if (str == null || str == '') return;
var arys = new Array();
arys = str.split('-');
var newDate = new Date(arys[0], arys[1] - 1, arys[2], 9, 0, 0);
if (ext) {
newDate = new Date(newDate.getTime() + 1000 * 60 * 60 * 24);
}
return newDate;
}
start="2012-02-24";
end="2012-02-27";
var date = new Date();
var start = strToDate(start);
var end = strToDate(end, false);
//document.write start.toString();
str="广告1";
str2="广告2";
if (date > start && date <end) {
document.write(str);
}else{
document.write(str2);
}
</script>
|
需要注意的是,这个是根据客户端的时间判定的,
代码如下 |
复制代码 |
start="2012-02-24";
end="2012-02-27";
|
实际是2.24与2.26号两天内显示的 |