日期 http://momentjs.com/
<script type="text/javascript">
date.prototype.format = function(format) {
var o = {
"m+": this.getmonth() + 1,
//month
"d+": this.getdate(),
//day
"h+": this.gethours(),
//hour
"m+": this.getminutes(),
//minute
"s+": this.getseconds(),
//second
"q+": math.floor((this.getmonth() + 3) / 3),
//quarter
"s": this.getmilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length));
for (var k in o)
if (new regexp("(" + k + ")").test(format)) format = format.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
return format;
}
// 日期相差天数
date.prototype.diff = function(date){
return math.ceil((this - date) / (1000 * 60 * 60 * 24));
// 日期加减计算
date.prototype.add = function(days){
return new date(this.gettime() + days * (1000 * 60 * 60 * 24));
date.prototype.addmonth = function(months){
var day = this.getdate();
var month = this.getmonth() + 1;
var year = this.getfullyear();
month += months;
if(month > 12){
year += math.floor(month / 12);
month = month % 12;
return date.parse(month + '/' + day + '/' + year);
var ddd = new date();
document.write(ddd.format('yyyy-mm-dd'));
</script>
对象
object.prototype.clone = function()
{
if(typeof(this) != "object")
return this;
var $clonedepth = (arguments.length >= 1) ? ((isnan(parseint(arguments[0]))) ? null : parseint(arguments[0])) : null;
if($clonedepth)
$clonedepth = ($clonedepth <= 0) ? null : $clonedepth;
var $cloneobject = null;
var $thisconstructor = this.constructor;
var $thisconstructorprototype = $thisconstructor.prototype;
if($thisconstructor == array)
$cloneobject = new array();
else if($thisconstructor == object)
$cloneobject = new object();
else
{
try
{
$cloneobject = new $thisconstructor;
}
catch(e)
$cloneobject = new object();
$cloneobject.constructor = $thisconstructor;
$cloneobject.prototype = $thisconstructorprototype;
var $propertyname = "";
var $newobject = null;
for($propertyname in this)
$newobject = this[$propertyname];
if(!$thisconstructorprototype[$propertyname])
if(typeof($newobject) == "object")
{
if($newobject === null)
$cloneobject[$propertyname] = null;
else
{
if($clonedepth)
{
if($clonedepth == 1)
$cloneobject[$propertyname] = $newobject;
else
$cloneobject[$propertyname] = $newobject.clone(--$clonedepth);
}
else
$cloneobject[$propertyname] = $newobject.clone();
}
}
else
$cloneobject[$propertyname] = $newobject;
return $cloneobject;
ss