Javascript 日期

来自ling
跳转至: 导航搜索
var firstdate = '11/01/2012';
var lastdate = '11/30/2012';

1. 很简单,没有所需的库:
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
或者你可能会喜欢:
var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);

2. 我也有datejs固定它 这是警报的优先天:
var fd = Date.today().clearTime().moveToFirstDayOfMonth();
var firstday = fd.toString("MM/dd/yyyy");
alert(firstday);
这是最后一天:
var ld = Date.today().clearTime().moveToLastDayOfMonth();
var lastday = ld.toString("MM/dd/yyyy");
alert(lastday);

<script language="javascript">
var d = new Date()()
var vYear = d.getFullYear()
var vMon = d.getMonth() + 1
var vDay = d.getDate()()
var h = d.getHours(); 
var m = d.getMinutes(); 
var se = d.getSeconds(); 
s=vYear+(vMon<10 ? "0" + vMon : vMon)+(vDay<10 ? "0"+ vDay : vDay)+(h<10 ? "0"+ h : h)+(m<10 ? "0" + m : m)+(se<10 ? "0" +se : se);
document.write(s);//输出时间
</script>