도야지

Date.prototype.toLocaleString() 본문

자바스크립트

Date.prototype.toLocaleString()

도야지밍 2023. 4. 20. 17:18
DateObject.toLocaleString([locales [, options])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat

 

Intl.DateTimeFormat() constructor - JavaScript | MDN

The Intl.DateTimeFormat() constructor creates Intl.DateTimeFormat objects.

developer.mozilla.org

 

예제(리액트)

function ExpenseItem(props) {
	const month = props.date.toLocaleString('en-US', {month: 'long'});
    const day = props.date.toLocaleString('en-US', {day: '2-digit'});
    const year = props.date.getFullYear();
    
    return(
    	<div className='expense-item'>
        	<div>
            	<div>{month}</div>
                <div>{year}</div>
                <div>{day}</div>
            </div>
        </div>
}

export default ExpenseItem;
Comments