Protobuf timestamp representation


I’m using google/protobuf/timestamp.proto in my protobuf objects.

I’d expect the response to be something like:

“created_at”: “2022-06-29T02:08:07.100Z”,

but instead I get the Timestamp response of something like (ignore actual dates, they wont match):

“created_at”: {
“seconds”: “1656466246”,
“nanos”: 85158000

Can I customize this behaviour?

You can’t customise it directly as that will be down to the API, but you can use the Tests tab to manipulate the format.

You can use something like the following to get a timestamp, and then use the moment library (which is included in the Postman sandbox) to format it however you want.

function toDateTime(secs) {
    var t = new Date(Date.UTC(1970, 0, 1)); // Epoch
    return t;

console.log(toDateTime(1656466246)); // Wed Jun 29 2022 02:30:46 GMT+0100 (British Summer Time)

I don’t really get the nanos part so don’t know if that is meant to be part of the calculation somehow.

I think this can also be converted using the following…

let date = "1656466246"

let toISOstring = (new Date(date * 1000)).toISOString();
console.log(toISOstring); // 2022-06-29T01:30:46.000Z

// using moment to format the date

var moment = require('moment');
var formattedDate2 = moment(toISOstring).format("DDMMYYYY");
console.log(formattedDate2); // 29062022