Maison  >  Article  >  interface Web  >  Prototype Date对象 学习_prototype

Prototype Date对象 学习_prototype

WBOY
WBOYoriginal
2016-05-16 18:50:151015parcourir

看一下源码:

复制代码 代码如下:

Date.prototype.toJSON = function() {
return '"' + this.getUTCFullYear() + '-' +
(this.getUTCMonth() + 1).toPaddedString(2) + '-' +
this.getUTCDate().toPaddedString(2) + 'T' +
this.getUTCHours().toPaddedString(2) + ':' +
this.getUTCMinutes().toPaddedString(2) + ':' +
this.getUTCSeconds().toPaddedString(2) + 'Z"';
};

其实就是返回Date的JSON字符串,下面给出示例:
复制代码 代码如下:

new Date(1969, 11, 31, 19).toJSON();
//-> '"1969-12-31T19:00:00"'

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn