js 转换时间戳的写法
来源:互联网 发布:ubuntu mate树莓派 编辑:程序博客网 时间:2024/05/29 17:01
- 自带方法
var time= new Date(毫秒)
- 函数加正则
function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); } alert(getLocalTime(1293072805));
3.自定义时间格式的方法(可自定义时间格式)
function changeDateFormat(cellval) { if (cellval != null) { var date = new Date(cellval); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var Hour = date.getHours(); var Min = date.getMinutes(); var Sen = date.getSeconds(); return date.getFullYear() + "-" + month + "-" + currentDate + " " + getCorr(Hour) + ":" + getCorr(Min) + ":" + getCorr(Sen); }}function getCorr(num) { if (parseInt(num) < 10) { num = '0' + num; } return num;}
4.大神写法(高度自定义)
// 转换时间戳 var format = function (time, format) { var t = new Date(毫秒); var tf = function (i) { return (i < 10 ? '0' : '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } }) } $("#statrtime").val(format(new Date().getTime(), 'yyyy/MM/dd HH:mm:ss'));
阅读全文
0 0
- js 转换时间戳的写法
- JS时间的不同写法
- js中时间的写法
- js 时间与时间戳的转换
- js 时间与时间戳的转换
- js 时间与时间戳的转换
- easyui中时间格式的转换写法
- js 时间戳转换时间
- js转换时间戳
- js 时间戳转换
- js日期和时间戳的转换
- js时间戳的相互转换
- JS获取当前时间戳的方法转换时间戳
- JS 将 格式化的时间 转换成 时间戳
- js 时间格式与时间戳的相互转换
- js时间戳和时间格式之间的转换
- JS 时间字符串与时间戳之间的转换
- js 时间戳转换为标准的时间格式
- Blued完成C和C+数亿元融资 Zank你怕了吗?
- 多线程3
- Linux 系统管理
- 深港澳汽车展:新能源、新技术汽车还有待发展
- golang入门基础
- js 转换时间戳的写法
- “国产最长寿手机”,金立靠什么?
- 支付宝六一强加“宝宝” 你拍砖还是点赞?
- Uber获35亿美元投资,无人驾驶汽车竞赛持续升级|智驾周刊
- 再说AI会威胁人类,一定是你没看这些|AI科技评论周刊
- 学习总结——android的消息机制handler
- 你离能够拥有一个“强AI”女友还有多久?让专家告诉你
- Java中throws和throw的区别讲解
- Redis--连接池