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
Helper methods that simplifies it, copy/paste the following on top of your JS:
Date.prototype.toUnixTime = function() { return this.getTime()/1000|0 };
Date.time = function() { return new Date().toUnixTime(); }
Now you can use it wherever you want by simple calls:
// Get the current unix time:
console.log(Date.time())
// Parse a date and get it as Unix time
console.log(new Date('Mon, 25 Dec 2010 13:30:00 GMT').toUnixTime())
Demo:
Date.prototype.toUnixTime = function() { return this.getTime()/1000|0 };
Date.time = function() { return new Date().toUnixTime(); }
// Get the current unix time:
console.log("Current Time: " + Date.time())
// Parse a date and get it as Unix time
console.log("Custom Time (Mon, 25 Dec 2010 13:30:00 GMT): " + new Date('Mon, 25 Dec 2010 13:30:00 GMT').toUnixTime())