LoginSignup
9
5

More than 3 years have passed since last update.

NUXTJS環境でmicroCMSで日付取得した際の省略方法

Posted at

自分用メモかねて。
公式ドキュメントにはなかったので、どちらかというとNUXT.JSの処理ですね。

microCMSをで投稿日とかを取得するには、

        "createdAt": "2020-09-24T11:27:31.580Z"
        "updatedAt": "2020-11-24T01:17:52.754Z"
        "publishedAt": "2020-09-24T11:27:31.580Z"

のように作成日、更新日、公開日を取得可能です。

ですが、例えば後ろの時刻まではいらないなーと思ったときには
処理が必要になります。
通常だと

      {{ publishedAt }}

(構成にもよりますが)
で出力ですが

      {{ new Date(publishedAt).toLocaleDateString() }}

と打つことで日付だけ取得可能でした。
スクリーンショット 2020-11-24 15.52.33.png
下が通常取得。上が処理後の取得。

9
5
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
9
5