Wednesday, June 11, 2014

Get date in Node.js using Javascript

To get date in Node.js, we can use javascript's Date object.

Example:
var http = require("http");
var url = require("url");

http.createServer(function(request, response){
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World!\n");
    response.write("from mobile-web-app.blogspot.com\n\n");
    
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth();
    var date = now.getDate();

    response.write(
        now + "\n");
    response.write(
        date + "/" + (month+1) + "/" + year + "\n");

    response.end();
}).listen(8888);



No comments:

Post a Comment