-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnode12.js
More file actions
47 lines (38 loc) · 1.08 KB
/
node12.js
File metadata and controls
47 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var http = require('http');
var url= require('url');
var port = process.argv[2];
function parsetime(time){
return{
"hour": time.getHours(),
"minute": time.getMinutes(),
"second": time.getSeconds()
};
}
function unixtime(time){
return{
"unixtime": time
};
}
var server = http.createServer(function (req,res) {
req.setEncoding("utf8");
var result = url.parse(req.url,true);//isoがキーになる
//var date = new Date(result.query.iso);
console.log(result);
var date = new Date(result.query.iso);
console.log("date=" + date);
if(result.pathname === '/api/parsetime'){
console.log(parsetime(date));
res.write(JSON.stringify(parsetime(date)));
res.end();
}else if(result.pathname === '/api/unixtime'){
date = date.getTime();
console.log(JSON.stringify(unixtime(date)));
res.write(JSON.stringify(unixtime(date)));
res.end();
};
})
server.listen(port)
/*
First argument must be a string or Buffer
サーバにオブジェクト型で返してしまった.
*/