angular.module('newApp')
.factory('dateUtil', function() {
var symbolMap = {
'MM': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getMonth();
}
return date.getMonth() + 1;
},
'mm': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getMinutes();
}
return date.getMinutes();
},
'YY': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getFullYear();
}
return date.getFullYear();
},
'ss': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getSeconds();
}
return date.getSeconds();
},
'hh': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getHours();
}
return date.getHours();
},
'dd': function(date) {
if (typeof(date) === 'string') {
var d = new Date(date);
return d.getDate();
}
return date.getDate();
}
}; function _makeNchar(char, n) {
var str = [];
while (n--) {
str.push(char);
}
return str.join('');
} function alignNumber(num, len, char) {
num = num + '';
if (num.length > len) {
return num;
} else {
return _makeNchar(char, len - num.length) + num;
}
} function getRelativeDate(offset, date) {
var relativeDate = new Date(date),
dateValue = relativeDate.getDate() + offset;
relativeDate.setDate(dateValue);
return relativeDate;
}return {
format: function(date, fmtStr) {
if (fmtStr) {
return fmtStr.replace((/(MM|mm|YY|ss|hh|dd)/g), function(s) {
return alignNumber(symbolMap[s](date), 2, '0');
});
}
},
getRelativeDate: getRelativeDate
};
});

最新文章

  1. AMap公交线路查询
  2. CSS3——动画效果
  3. 【BZOJ-3293&1465&1045】分金币&糖果传递×2 中位数 + 乱搞
  4. hdu 2052
  5. single page
  6. PHP 字符串替换 substr_replace 与 str_replace 函数
  7. codeblocks 使用指南z
  8. Linux入门基础 #10:命令行文本处理工具
  9. 经excel要将数据库(ORACLE)要插入数据
  10. 50行代码实现的高性能动画定时器 raf-interval
  11. CF每日一练 Codeforces Round #520 (Div. 2)
  12. url的参数解析成key-value
  13. 如何将他人的SOPC工程转换为自己可以使用的工程
  14. numpy元素级数组函数
  15. 实力封装:Unity打包AssetBundle(番外篇)
  16. 并发编程之 线程协作工具 LockSupport
  17. Android WebView漏洞(转)
  18. 《Java性能优化权威指南》
  19. 关于直播学习笔记-004-nginx-rtmp、srs、vlc、obs
  20. rertful规范

热门文章

  1. 03—AOP基本配置
  2. Ceph在手,天下我有
  3. C++ const学习
  4. get、post、put、delete、head请求方式
  5. 深度优先搜索DFS和广度优先搜索BFS简单解析
  6. ZENCART 二级 分类 展开
  7. Codeforces_765_D. Artsem and Saunders_(数学)
  8. codeforces_456C_dp
  9. 从Element.getElementsByTagName方法说起
  10. Functional language 函数