A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/toString below:

Date.prototype.toString() - JavaScript | MDN

Date.prototype.toString()

Baseline Widely available

toString() 메서드는 Date 객체의 시간을 문자열로 반환합니다.

시도해 보기
const event = new Date("August 19, 1975 23:15:30");

console.log(event.toString());
// Expected output: "Tue Aug 19 1975 23:15:30 GMT+0200 (CEST)"
// Note: your timezone may vary
구문 반환 값

주어진 날짜를 나타내는 문자열.

설명

Date 객체는 toString() 메서드를 Object.prototype이 아닌 Date.prototype에서 상속받습니다. Date.prototype.toString()의 반환값은 ECMA-262에 명시되어있으며 다음과 같이 요약할 수 있습니다.

예: "Sat Sep 01 2018 14:53:26 GMT+0900 (KST)"

ECMAScript 2018(제9판) 전까지 toString()의 반환 형식은 구현에 따라 다를 수 있었습니다. 따라서 특정 형식에 의존하지 않아야 합니다.

toString() 메서드는 날짜를 문자열로 표현해야 할 때 자동으로 쓰입니다. console.log(new Date())와 const today = 'Today is ' + new Date() 등의 경우를 예로 들 수 있습니다.

toString()은 제네릭 메서드로 this의 값이 Date일 필요는 없습니다. 그러나 내부적으로 [[TimeValue]] 속성이 필요한데, 이는 JavaScript로는 설정할 수 없어 결국 사용이 Date 인스턴스로 제한됩니다. Date 외의 다른 객체에서 호출하면 TypeError가 발생합니다.

예제 toString() 사용
var x = new Date();
var myVar = x.toString(); // assigns a string value to myVar in the same format as:
// Mon Sep 08 1998 14:36:22 GMT+0900 (KST)
명세 브라우저 호환성 같이 보기

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4