Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 有没有办法将unix时间戳存储在NodeJS缓冲区中?_Node.js_Buffer - Fatal编程技术网

Node.js 有没有办法将unix时间戳存储在NodeJS缓冲区中?

Node.js 有没有办法将unix时间戳存储在NodeJS缓冲区中?,node.js,buffer,Node.js,Buffer,需要从UNIX时间戳创建缓冲区以将其保存在bsv区块链上。 尝试此解决方案: let buffer = Buffer.allocUnsafe(10); buffer.writeUInt16BE(Date.now()); 但是得到一个错误: RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received 1568909911723

需要从UNIX时间戳创建缓冲区以将其保存在bsv区块链上。 尝试此解决方案:

let buffer = Buffer.allocUnsafe(10);
buffer.writeUInt16BE(Date.now());
但是得到一个错误:

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received 1568909911723
    at checkInt (internal/buffer.js:35:11)
    at writeU_Int16BE (internal/buffer.js:653:3)
    at Buffer.writeUInt16BE (internal/buffer.js:661:10)
RangeError[错误超出范围]:值超出范围。它必须大于等于0且请尝试以下操作:

    let bignum = require('bignum');
    let opts= {endian:'big',size:6 /*6-byte / 48-bit*/}
    let dt = Date.now();
    console.log(dt);
    let num = bignum(dt.toString());
    var buf = num.toBuffer(opts);
    let a = bignum.fromBuffer(buf,opts)
    console.log(a.toNumber());

请同时阅读以下内容:。将有助于理解核心概念

您是否尝试过下面的解决方案?