时间格式化输出
来源:互联网 发布:js 工作流设计器 编辑:程序博客网 时间:2024/05/22 03:27
function formatDate(t, str) {
var obj = {
yyyy:t.getFullYear(),
yy:(""+ t.getFullYear()).slice(-2),
M:t.getMonth()+1,
MM:("0"+ (t.getMonth()+1)).slice(-2),
d:t.getDate(),
dd:("0" + t.getDate()).slice(-2),
H:t.getHours(),
HH:("0" + t.getHours()).slice(-2),
h:t.getHours() % 12,
hh:("0"+t.getHours() % 12).slice(-2),
m:t.getMinutes(),
mm:("0" + t.getMinutes()).slice(-2),
s:t.getSeconds(),
ss:("0" + t.getSeconds()).slice(-2),
w:['日', '一', '二', '三', '四', '五', '六'][t.getDay()]
};
return str.replace(/([a-z]+)/ig,function($1){return obj[$1]});
}
定义一个对象,将事件参数作为对象属性传入,其中,getmonth要+1,slice(-2)取后两位,在加判断之前,先要考虑下能不能用一些简便的运算统一一下,如:%12.
str.replace()方法,第一个参数为正则,第二个传入的参数是正则匹配到的参数,依次执行函数进行替换。
0 0
- javascript格式化时间输出
- android格式化输出时间
- 格式化输出时间
- struts2格式化输出时间
- PHP 时间格式化输出
- 时间格式化输出SimpleDateFormat
- 格式化输出当前时间
- 时间格式化输出
- PHP格式化时间输出
- 时间格式化输出
- 时间格式化输出
- 格式化输出日期和时间
- 格式化输出日期和时间
- informix日期时间格式化输出
- VC++基础 格式化时间输出
- Perl格式化输出时间日期
- jsp页面格式化时间输出
- JAVA DATEFORMAT 格式化时间输出
- UML实践详细经典教程----用例图、顺序图、状态图、类图、包图、协作图
- perl正则表达式(一)
- 【C++】:STL迭代器使用详解,很好很详细
- struts中数据处理
- 57-003-1 bootstrap附加导航Affix实现页面的滚动监听
- 时间格式化输出
- 数据库增删改查之增
- 涛哥的Cocos2d-js教程 之一 js绑定 读取csb文件
- Android 项目框架 使用MVP开发
- 关于联合体
- haroxy hdr
- Eclipse exits automatically exit code 127
- RHEL7软件包管理
- 第103课:动手实战联合使用Spark Streaming、Broadcast、Accumulator实现在线黑名单过滤和计数