From: Aleksander Ɓukasz Date: Fri, 21 Mar 2014 11:54:03 +0000 (+0100) Subject: fnpjs: datetime X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/8244aae227025150a77d6377caa52e0b7b0b5cbc fnpjs: datetime --- diff --git a/src/fnpjs/datetime.js b/src/fnpjs/datetime.js new file mode 100644 index 0000000..7ebee12 --- /dev/null +++ b/src/fnpjs/datetime.js @@ -0,0 +1,30 @@ +define(function() { + +'use strict'; + +var pad = function(number) { + if(number < 10) { + number = '0' + number; + } + return number; +}; + +var defaultFormat = '%d-%m-%y %H:%M:%S'; + +return { + strfmt: function(datetime, format) { + format = format || defaultFormat; + return format + .replace('%d', pad(datetime.getDate())) + .replace('%m', pad((datetime.getMonth() + 1))) + .replace('%y', pad(datetime.getFullYear())) + .replace('%H', pad(datetime.getHours())) + .replace('%M', pad(datetime.getMinutes())) + .replace('%S', pad(datetime.getSeconds())); + }, + currentStrfmt: function(format) { + return this.strfmt(new Date(), format); + } +}; + +}); \ No newline at end of file