LoginSignup
5
1

More than 3 years have passed since last update.

Unix timestampとDate time間の変換 #PowerAutomate

Posted at

Unix timestampとdate timeを変換する処理をPower Automateで結構利用するので、備忘録として残しておきます。

Date time → Unix timestamp

入力がDate time (yyyy-mm-dd等)でUnix timestamp (秒単位)にしたい場合には

div(sub(ticks('ここにDate time'),ticks('1970-01-01')), 10000000)

例えばConvert time zoneの結果を使う場合には、

div(sub(ticks(body('Convert_time_zone')),ticks('1970-01-01')), 10000000)

ticks関数は西暦を100ナノ秒単位で返す関数なので、これを利用して、1970-01-01におけるナノ秒との差分を求めて、その後ナノ秒→秒にするために割り算する

Unix timestamp → Date timeの変換

入力が秒単位のUnix timestampで、これをDate timeに直す場合には、

addseconds('1970-1-1', ここにUnix timestamp (数値), 'yyyy-MM-dd HH:mm')

もとの数式は addSeconds('<timestamp>', <seconds>, '<format>'?) この書式なので、1970-01-01にUnix timeを足せば、Date timeに指定のフォーマットで変換できる

動作確認

実際Convert time zoneでutcNow()をJSTに変換したあとにUnix timestampに変換し、その結果を再変換してみると以下のようになる。

image.png

Reference

Ticks関数: https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#ticks

addSeconds関数: https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#addSeconds

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