<script type="text/javascript">
$(function(){
String.prototype.format = function() {
var vs = arguments;
return this.replace(/\{(\d+)\}/g, function() { return vs[parseInt(arguments[1])]; });
};
Date.prototype.format = function(formatString) {
with (this) {
return (formatString||"{0}-{1}-{2} {3}:{4}:{5}").format(
getFullYear()
, ("0" + (getMonth()+1)).slice(-2)
, ("0" + getDate()).slice(-2)
, ("0" + getHours()).slice(-2)
, ("0" + getMinutes()).slice(-2)
, ("0" + getSeconds()).slice(-2)
);
}
};
function getWeek(theDay) {
var monday = new Date(theDay.getTime());
var sunday = new Date(theDay.getTime());
monday.setDate(monday.getDate()+1-monday.getDay());
sunday.setDate(sunday.getDate()+7-sunday.getDay());
return {monday:monday, sunday:sunday};
}
var week = getWeek(new Date('2014/1/4'));
alert(
week.monday.format("{0}.{1}.{2}")
+ " - " +
week.sunday.format("{0}.{1}.{2}")
);
})
</script>
js自动计算给定日期所在周的周一与周日对应的日期
最新推荐文章于 2023-02-09 09:36:30 发布