-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex13.js
22 lines (22 loc) · 804 Bytes
/
ex13.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var input = process.argv[2];
var http = require('http');
var url = require('url');
var server = http.createServer(function(request, response){
var parsed = url.parse(request.url, true);
if(parsed.pathname==="/api/parsetime"){
response.writeHead(200, {'Content-Type': 'application/json'});
var dato = new Date(parsed.query.iso);
var jsonResponse = JSON.stringify({hour: dato.getHours(), minute: dato.getMinutes(), second: dato.getSeconds()});
response.end(jsonResponse);
}
else if(parsed.pathname==="/api/unixtime"){
response.writeHead(200, {'Content-Type': 'application/json'});
var dato = new Date(parsed.query.iso);
var jsonResponse = JSON.stringify({unixtime: dato.getTime()});
response.end(jsonResponse);
}
else{
response.writeHead(404);
response.end();
}
}).listen(input);