Created
May 15, 2020 08:40
-
-
Save aimtiaz11/db0430c211ec312661abc8632fb812ea to your computer and use it in GitHub Desktop.
Postman Calculate Date and Timstamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const moment = require('moment'); | |
| pm.globals.set("todaysDate", moment().format("YYYY-MM-DD")); | |
| const TimeZoneUTCOffsetMapping = { | |
| 'Australia/Sydney': 11 | |
| }; | |
| const LocalUTCOffset = 11; | |
| function getMomentDisplayInTimeZone(momentObj, timeZone) { | |
| let timeZoneUTCOffset = TimeZoneUTCOffsetMapping[timeZone]; | |
| if (timeZoneUTCOffset === undefined) { | |
| throw new Error('No time zone matched'); | |
| } | |
| return momentObj.add(timeZoneUTCOffset - LocalUTCOffset, 'hour').format('YYYY-MM-DDTHH:mm:ss.SSSZ'); | |
| } | |
| pm.globals.set("currentTimestampWithTz", getMomentDisplayInTimeZone(moment(), 'Australia/Sydney')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment