Home > Web Front-end > JS Tutorial > body text

Prototype Date object learning_prototype

WBOY
Release: 2016-05-16 18:50:15
Original
1056 people have browsed it

Take a look at the source code:

Copy the code The code is as follows:

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

actually returns the JSON string of Date. An example is given below:
Copy code The code is as follows:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!