What can I use to determine today's UTC time period provided today is 2017-11-17 Pacific?

Problem Statement:
Given DAY, i.e. (time zone: Pacific) 2017-11-17, need a converter to produce UTC time period for telemetry reading, i.e. start=2017-11-17T08:00:00.000000Z&end=2017-11-18T07:59:59.999999Z.

Is there such a formula or method to do this?

Thanks in advance for your help!
Tien.

You can require moment, which is available in the Postman Sandbox for this.

This pre-request script should work

const moment = require('moment');

const today = moment();

pm.globals.set('startDayUTC', today.startOf('day').toISOString());
pm.globals.set('endDayUTC', today.endOf('day').toISOString());

This will pick the local timezone of the computer running the collection. If you want to force to PST, then initialize today like so

const today = moment().zone(420);  // PST offset from UTC in minutes

// Or for UTC
const today = moment.utc();

More on setting timezone offset in moment here

4 Likes

Thank you for your help, Akshay. I will check this out!! And update the post accordingly.

Thanks,
Tien

works awesome as I finally got around to making use of this !!

thanks again, Akshay.

@akshaybist, the real MVP.

J

Thanks, Chris.

Tien