This page was translated from English by the community.Learn more and join the MDN Web Docs community.
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 객체의 문자열 표현을 반환합니다.
In this article
시도해 보기
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> |