12
4

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.

GitHub Actionsで現在日時を取得する

Last updated at Posted at 2021-09-25

GitHub Actionsで現在日時を取得する必要があったため、その方法をまとめておきます。

.github/workflows/get_current_datetime.yml
name: "Get current datetime"

on: [ workflow_dispatch ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Set current datetime as env variable
        env:
          TZ: 'Asia/Tokyo' # タイムゾーン指定
        run: echo "CURRENT_DATETIME=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV

      - name: Show current datetime
        run: echo ${{ env.CURRENT_DATETIME }}

Set current datetime as env variable の部分で、環境変数 CURRENT_DATETIME に現在日時を入れています。
タイムゾーンは、 TZ: 'Asia/Tokyo' のように指定します。
'%Y-%m-%d %H:%M:%S' の部分で、フォーマットを指定可能です。
この例では 2021-09-26 00:00:00 のような形式になります。

以降は、 ${{ env.CURRENT_DATETIME }} のように現在日時を取得可能です。

12
4
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
12
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?