Skip to content

Instantly share code, notes, and snippets.

@dtryon
Created February 25, 2012 22:21
Show Gist options
  • Save dtryon/1911166 to your computer and use it in GitHub Desktop.
Save dtryon/1911166 to your computer and use it in GitHub Desktop.
first crack at a module in node.js
var DateFormatter = {
format: function(d) {
var d_date = d.getDate();
var d_month = d.getMonth();
d_month++;
var d_year = d.getFullYear();
var a_p = '';
var d_hour = d.getHours();
if (d_hour < 12)
{
a_p = 'AM';
}
else
{
a_p = 'PM';
}
if (d_hour == 0)
{
d_hour = 12;
}
if (d_hour > 12)
{
d_hour = d_hour - 12;
}
var d_min = d.getMinutes();
d_min = d_min + '';
if (d_min.length == 1)
{
d_min = '0' + d_min;
}
return d_date + '/' + d_month + '/' + d_year + ' ' + d_hour + ' : ' + d_min + ' ' + a_p;
}
}
exports.DateFormatter = new DateFormatter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment