The source code for a public API that I run.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

43 lines
1.3 KiB

var respond = function(res, answer){
res.writeHead(200,{
'Content-Type': 'application/javascript'
});
return res.end(JSON.stringify(answer));
};
module.exports = function(server){
server.get('/time/epoch', function(req, res){
return respond(res, parseInt(new Date().getTime()/1000));
});
server.get('/time/utc', function(req,res){
var answer = {};
var now = new Date();
answer.epoch = parseInt(now.getTime()/1000);
answer.month = now.getUTCMonth()+1;
answer.day = now.getUTCDate();
answer.year = now.getUTCFullYear();
answer.hours = now.getUTCHours();
answer.minutes = now.getUTCMinutes();
answer.seconds = now.getUTCSeconds();
answer.milliseconds = now.getUTCMilliseconds();
answer.day_of_week = now.getUTCDay();
return respond(res, answer);
});
server.get('/time', function(req, res){
var answer = {};
var now = new Date();
answer.epoch = parseInt(now.getTime()/1000);
answer.month = now.getMonth()+1;
answer.day = now.getDate();
answer.year = now.getFullYear();
answer.hours = now.getHours();
answer.minutes = now.getMinutes();
answer.seconds = now.getSeconds();
answer.milliseconds = now.getMilliseconds();
answer.day_of_week = now.getDay();
answer.timezone_offset = -(now.getTimezoneOffset()/60);
return respond(res, answer);
});
};