59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
|
/**
|
||
|
* @file server_utils.js
|
||
|
* @author frtk
|
||
|
*/
|
||
|
|
||
|
|
||
|
/**
|
||
|
* lib : DateLib
|
||
|
* purpose : date utils
|
||
|
*/
|
||
|
var datelib = {
|
||
|
|
||
|
//--- dateToString
|
||
|
dateToString: function(date) {
|
||
|
var self = this;
|
||
|
return '[' + self.addZero(date.getHours(), 'h') + ':'
|
||
|
+ self.addZero(date.getMinutes(), 'm') + ':'
|
||
|
+ self.addZero(date.getSeconds(), 's') + ':'
|
||
|
+ self.addZero(date.getMilliseconds(), 'ms') + ']';
|
||
|
},
|
||
|
|
||
|
//--- addZero
|
||
|
addZero: function(value, type) {
|
||
|
switch(type) {
|
||
|
case 'h':
|
||
|
case 'm':
|
||
|
case 's':
|
||
|
if (value < 10) value = '0' + value;
|
||
|
break;
|
||
|
case 'ms':
|
||
|
if (value < 10) value = '00' + value;
|
||
|
else if (value >= 10 && value < 100) value = '0' + value;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
};
|
||
|
return value;
|
||
|
},
|
||
|
|
||
|
//--- return new date string
|
||
|
newDateToString: function() {
|
||
|
var self = this;
|
||
|
return self.dateToString(new Date());
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* EXPORTS
|
||
|
*
|
||
|
*/
|
||
|
if (typeof exports !== "undefined") {
|
||
|
//--- Objects
|
||
|
exports.datelib = datelib;
|
||
|
}
|