How to generate timestamp unix epoch format nodejs?

后端 未结 7 1729
感动是毒
感动是毒 2021-01-31 06:54

I am trying to send data to graphite carbon-cache process on port 2003 using

Ubuntu terminal:

echo "test.average 4 `date +%s`" | nc -q0 127.0.0.1         


        
7条回答
  •  时光取名叫无心
    2021-01-31 07:34

    If you can, I highly recommend using moment.js. To get the number of milliseconds since UNIX epoch, do

    moment().valueOf()
    

    To get the number of seconds since UNIX epoch, do

    moment().unix()
    

    You can also convert times like so:

    moment('2015-07-12 14:59:23', 'YYYY-MM-DD HH:mm:ss').valueOf()
    

    I do that all the time.

    To install moment.js on Node,

    npm install moment
    

    and to use it

    var moment = require('moment');
    moment().valueOf();
    

    ref

提交回复
热议问题