Timestamp in pre-execution script for HTPP monitors

I am posting data points in pre-execution script and dont know how to create timestamp, trying Date.parse(api.date()) below, What’s the correct way to do this ?

requestBody={<br>"type": "LB",<br>"series": [<br>{<br>"timeseriesId": "custom:alteon.CurrSessions",<br>"dimensions": {<br>"CUSTOM_DEVICE": "Load Balancers"<br>},<br>"dataPoints": [<br>[<br>Date.parse(api.date()),<br>api.randomNextInt()<br>]<br>]<br>}<br>]<br>};<br>request.setBody(requestBody);

I would use a variable and get the value before you start to create the requestBody. Something like this:

var timestampNow = api.date();

and then use the variable later. Or if you need it to be in a specific format you can use api.dateToFormat. You can find a couple of examples here