From 310f452b9eb32df8d154ee3cb01723cfeddd79cb Mon Sep 17 00:00:00 2001 From: Sanal Thekkanath Date: Fri, 9 Feb 2024 11:43:45 -0800 Subject: [PATCH] adding script to convert epoc current millisecis to UTC/Local date time str --- Scripts/EPOCMilliSecsToDateTime.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 Scripts/EPOCMilliSecsToDateTime.js diff --git a/Scripts/EPOCMilliSecsToDateTime.js b/Scripts/EPOCMilliSecsToDateTime.js new file mode 100755 index 00000000..ef681a27 --- /dev/null +++ b/Scripts/EPOCMilliSecsToDateTime.js @@ -0,0 +1,24 @@ +/** + { + "api":1, + "name":"EPOCMilliSecs to Date Time", + "description":"Convert EPOC Millisecond to UTC/Local date time string", + "author":"Sanal Kumar", + "icon":"link", + "tags":"date,time,calendar,unix,timestamp" + } +**/ + +function main(input) { + const isEpochMillisFormat = (str) => { + const regex = /^\d{13}$/; + return regex.test(str); + }; + let parsedEpocMilliseconds = parseInt(input.text) + if (!isEpochMillisFormat(input.text)) { + input.postError("Invalid EPOC Millisecond Input") + } else { + input.text = new Date(parsedEpocMilliseconds).toUTCString() + "( Local Time : "+new Date(parsedEpocMilliseconds)+")" + } +} +