概要
Power Automate DesktopでUNIX時間を日本標準時(JST)に変換します。某APIのドキュメントで見慣れない時間表記があったので調べました。下記のようなJSONで「1234567890」っていつのこと?Power Automate Desktopではどのように変換するんだという話です。
JSON
{
"order": [
{
"key": "abcd",
"orderdatetime": 1234567890,
"dispatched": 1235431895
},
{
"key": "abce",
"orderdatetime": 1235531898,
"dispatched": 1236895896
}
]
}
環境
- Windows 10Pro 21H1
- Power Automate Desktop 2.13.163.21263
注意事項等
- 2021年10月の情報です。
- Windows 11の環境は持っていないので試していません。
- 私が使用しているバージョンでの表記はPower Automate DesktopとなっているためPower Automate for Desktopにしていません。
UNIX時間のこと
ざっくりまとめると
UNIXエポック(協定世界時1970年1月1日午前0時0分0秒)から形式的な経過秒数で表した時刻表現とのこと。これならPower Automate Desktopのフロー内で変換できそうです。
フロー
-
Set variable
変数名を %UnixBaseTimeJST%
日本標準時(JST)は協定世界時(UTC) +9時間なので、UNIXエポック(協定世界時1970年1月1日午前0時0分0秒に9時間を足した値を宛先に設定します。
%D'1970/01/01 09:00:00'%
PowerAutomateDesktop
Display.InputDialog Message: $'''Input UnixTime''' InputType: Display.InputType.SingleLine IsTopMost: False UserInput=> UnixTime ButtonPressed=> ButtonPressed
SET UnixBaseTimeJST TO D'1970/01/01 09:00:00'
DateTime.Add DateTime: UnixBaseTimeJST TimeToAdd: UnixTime TimeUnit: DateTime.TimeUnit.Seconds ResultedDate=> ResultedDateJST
Display.ShowMessage Message: ResultedDateJST Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
まとめ
これだけです💦
UNIX時間「1234567890」のような表記がでてきても大丈夫そうです。
「1234567890」がいつなのかは試してください!
2038年問題なんてあるんですねw