【GitHub Actions】タイムゾーンを指定して現在日時を取得する

Git/Github

GitHub Actionsで現在の日時を取得する方法をメモしておきます。
タイムゾーンや時刻表記は任意に変更可能です。

name:  Show current date
on: [push]
jobs:
  build:
    name:  Show current date
    runs-on: ubuntu-latest
    steps:
      - name: Get current date and time
        env: 
          TZ: "Asia/Tokyo" # タイムゾーンを指定
        id: date
        run: echo "::set-output name=date::$(date +'%Y-%m-%d %H:%M')"
       # '%Y-%m-%d %H:%M'の部分を書き換えれば、任意の表示に変更できる。

      - name: Show date and time
        run: echo ${{ steps.date.outputs.date }} # 2022-01-03 10:42

タイトルとURLをコピーしました