# Is there a way to convert "Timestamp" say "2020-08-06T08:18:12.500Z" to "UTCTimestamp": "1596701892" or Vice versa?

**URL:** <https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [August 7, 2020, 6:07am UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809 "2020-08-07T06:07:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![avinash.balekundri](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@avinash.balekundri](https://community.postman.com/u/avinash.balekundri)\
**Post date:** [August 7, 2020, 6:07am UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809/1 "2020-08-07T06:07:07Z")

</div>

My postman response body looks something like this:

```auto
{
    "GetServerTimeResponse": {
        "Timestamp": "2020-08-06T08:18:12.500Z",
        "UTCTimestamp": "1596701892",
    }
}

```

How to make sure Timestamp and UTCTimestamp are equal?

Either I can convert Timestamp to UTCTimestamp and say both strings match or convert UTCTimestamp to Timestamp and say both strings are matching?

In Java langauge, I know this is how we do. But would be interested to know how to do in postman scripts:

```auto
//Verify time
String timeStamp = new Long(responseType.getTimestamp().getTimeInMillis()/1000).toString();
String UTCTimestamp = responseType.getUTCTimestamp();
test.assertValue("TimeStamps are equal", timeStamp, UTCTimestamp);

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 7, 2020, 7:13am UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809/2 "2020-08-07T07:13:49Z")

</div>

Hey @avinash.balekundri

Welcome to the community and thank you for posting the question! 🤖

Postman comes with [moment](https://momentjs.com/docs/) built-in which is awesome for working with dates and times in Javascript.

You could use something like this to convert the 2 timestamps and then use the `isSame()` method to do the compression.

```auto
let moment = require('moment'),
    jsonData = pm.response.json()
    Timestamp = jsonData.GetServerTimeResponse.Timestamp,
    UTCTimestamp = jsonData.GetServerTimeResponse.UTCTimestamp

console.log(moment.unix(UTCTimestamp).isSame(moment(Timestamp)))

```

I’ve just logged that out to the console for now but you could also wrap that in a test:

```auto
pm.test("Timestamps are equal", () => {
    pm.expect(moment.unix(UTCTimestamp).isSame(moment(Timestamp))).to.be.true
})

```

---

<div class="post-metadata">

**Author:** ![avinash.balekundri](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@avinash.balekundri](https://community.postman.com/u/avinash.balekundri)\
**Post date:** [August 11, 2020, 6:43am UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809/3 "2020-08-11T06:43:05Z")

</div>

thanks danny. It worked for me. This is what i was looking for.

---

<div class="post-metadata">

**Author:** ![graham-carter](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@graham-carter](https://community.postman.com/u/graham-carter)\
**Post date:** [February 7, 2022, 12:03pm UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809/4 "2022-02-07T12:03:17Z")

</div>

Hi guys,  
on a similar theme, is there a way to validate that the timestamp in a response is in the unix timestamp format?  
We currently just verify that the timestamp field is returned:  
});

pm.test(“Body matches string”, function () {

```
pm.expect(pm.response.text()).to.include("timestamp");

```

});

but we now need to check that the format is correct, ie “timestamp”: 1624007506

many thanks for any help on this!

Graham

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [August 23, 2023, 3:43pm UTC](https://community.postman.com/t/is-there-a-way-to-convert-timestamp-say-2020-08-06t0812-500z-to-utctimestamp-1596701892-or-vice-versa/14809/5 "2023-08-23T15:43:24Z")

</div>

Closed on August 23, 2023, 3:43pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
