Date.prototype.toJSON()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
toJSON() ë©ìëë Date ê°ì²´ì 문ìì´ ííì ë°íí©ëë¤.
ìëí´ ë³´ê¸°
const event = new Date("August 19, 1975 23:15:30 UTC");
const jsonDate = event.toJSON();
console.log(jsonDate);
// Expected output: "1975-08-19T23:15:30.000Z"
console.log(new Date(jsonDate).toUTCString());
// Expected output: "Tue, 19 Aug 1975 23:15:30 GMT"
구문
js
dateObj.toJSON();
ë°í ê°
주ì´ì§ ë ì§ì 문ìì´ íí.
ì¤ëª
Date ì¸ì¤í´ì¤ë ìê°ì í¹ì ì§ì ì ê°ë¦¬íµëë¤. toJSON()ì í¸ì¶íë©´ toISOString() ì¬ì©í´ ê·¸ ì¸ì¤í´ì¤ê° ê°ë¦¬í¤ë ìê°ì 문ìì´ ííì ë°íí©ëë¤. toJSON()ì Date ê°ì JSONì¼ë¡ ì§ë ¬íí ë ì ì©íê² ì¬ì©í ì ìëë¡ ë§ë¤ì´ì¡ìµëë¤.
ìì
>toJSON() ì¬ì©í기
js
const jsonDate = new Date().toJSON();
const backToDate = new Date(jsonDate);
console.log(jsonDate); //2015-10-26T07:46:36.611Z
ëª ì¸
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-date.prototype.tojson > |