์ƒˆ์†Œ์‹

๐Ÿ“ŒDevelop/โš›๏ธReact

[React] date format / moment / react YYYYMMDD YYYY-MM-DD

  • -

 

const currentDate = new Date() console.log(currentDate) //Output: 2022-01-29T10:03:47.564Z

์ด์ œ๊ป ๋ด์™”๋˜ Javascript์˜ ํ˜•์‹์ด๋‹ค!

๐Ÿ“npm ๋˜๋Š” yarn ์„ ์ด์šฉํ•œ ์„ค์น˜ ๋ช…๋ น์–ด

$ npm install moment --save // ๋˜๋Š” $ yarn add moment

import "./index.css" import Moment from 'moment'; import "moment/locale/ko"; // Locale Setting function App() { const formatDate = Moment().format('YYYY-MM-DD') /* * Year : YYYY * Month : MM * Day : DD * Hour : HH * Min : mm * Sec : ss */ return ( <div className='container'> <h1>{formatDate}</h1> </div> ); } export default App;

// format์— ๋งž๊ฒŒ ์ถœ๋ ฅ๋œ๋‹ค. const nowTime = moment().format('YYYYMMDD HH:mm:ss'); console.log(nowTime); // ์ถœ๋ ฅ ๊ฒฐ๊ณผ: 20210818 09:41:32

 

 

 

๋ฐ˜์‘ํ˜•

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.