Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Unix time as integer format in Google Apps Script

I'd like to use unix time stamp for count-up nonce in GAS.

var nonce = Math.floor((date.getTime()/1000))

is my first idea. But GAS handles this variant as 1.482239855E9 - 9th Gig format - instead of 1482239855.
When I connect it with other strings, it shows 1482239855my_string, which is good.

The problem is I send this nonce to server with encrypted 1482239855my_string for authentication then the nonce will not match as 1.482239855E9 vs 1482239855.
How can I get this nonce as integer format? In spreadsheet, I know setNumberFormat("0") method in range. Is there a similar method or properties?

like image 876
M_Igashi Avatar asked Oct 26 '25 23:10

M_Igashi


1 Answers

The variable nonce is already an integer, the exponential format is just how it is presented for display on screen by Logger.log. Its string representation obtained with toString (which is also called implicitly when you concatenate with another string) has ordinary format, and can be safely used for information exchange.

var date = new Date();
var nonce = Math.floor((date.getTime()/1000)).toString(); // is "1482247966"