1
console.og(Date.now() & 0xffffffff)

I got -1798272874 which is not what I want, I want a positive integer not a negative number.

guilin 桂林
  • 17,050
  • 29
  • 92
  • 146

2 Answers2

0

Maybe this can help you.

var date = Date.now();
var bytes = new Array();
for (i = 0; i < 4; i++) {
    bytes[i] = (date >> (8*i)) & 0xff;
}
console.log(bytes);

Got the operation from here

Community
  • 1
  • 1
Salvador P.
  • 1,469
  • 19
  • 16
0

If you zero-fill right shift (>>>) by 0 bits, JavaScript will give you an unsigned representation of the number. So your code from above would become,

console.log((Date.now() & 0xffffffff) >>> 0)

which will result in something like 2497628378.

See this stackoverflow question and the MDN documentation for zero-fill right shift for more information.

Community
  • 1
  • 1
lostriebo
  • 1,483
  • 1
  • 16
  • 25