Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created November 26, 2012 14:57
Show Gist options
  • Save cianclarke/4148623 to your computer and use it in GitHub Desktop.
Save cianclarke/4148623 to your computer and use it in GitHub Desktop.
Date time tutorial cloud code
var util = require('util');
var request = require('request');
exports.getCurrentTime = function(params, callback) {
request({uri : 'http://www.timeanddate.com/worldclock/city.html?n=78'}, function(err, response, body){
return callback(null, {
'response' : body
});
});
}
exports.getCurrentTimeRegEx = function(params, callback) {
request({uri : 'http://www.timeanddate.com/worldclock/city.html?n=78'}, function(err, response, body){
// Construct a regular expression to extract the date and time from the response
var reg = /(<strong id=ct[^>]*>)([^<]*)/;
//Extract the required info
var dateMatch = reg.exec(body);
return callback(null, {
'response' : dateMatch[2]
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment