0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Next.jsでAPI取得した日時の表示形式を変更する

Posted at

今回はMicroCMSから取得した日付が、
[2021-06-09T05:53:07.635Z]
みたいな感じで、見づらかったので、変更方法をメモリます。

(1)yarn add react-moment

(2)APIを取得しているファイルで

index.tsx
import Moment from 'react-moment'

//(省略)

<div className={styles.contents}>
  <h1 className={styles.title}>{blog.title}</h1>
  <Moment format="YYYY/MM/DD" className={styles.date}>
    {blog.publishedAt}
  </Moment>
  <img src={blog.thumbnail.url} className={styles.thumbnail}></img>
  <div
    className={styles.main}
    dangerouslySetInnerHTML={{
      __html: `${blog.main}`,
    }}
  />

ってやれば、変更できる!おっけっけ!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?