时间戳格式化转换为日期格式,date.Format('yyyy/MM/dd hh:mm:ss')
2017-12-07 14:50
921 查看
调用如下方法即可,给Date的原型增加自定义的格式化方法:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script type="text/javascript"> Date.prototype.Format = function(fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } function timestamp_to_datetime(ts) { var date = new Date(ts * 1000); return date.Format('yyyy/MM/dd hh:mm:ss') } var date_str = timestamp_to_datetime(1512622621); console.log(date_str); //2017/12/07 12:57:01 </script> </body> </html>
相关文章推荐
- 利用SimpleDateFormat 和MessageFormat 向数据库中插入yyyy-mm-dd 和yyyy-MM-dd HH:mm:ss的日期格式
- Java 原始 date格式的日期如何手动转成yyyy-MM-ss HH:dd
- 将字符串"yyyy-MM-dd'T'hh:mm:ss"转换其他时间格式
- 在EL表达式或者Struts标签库中格式化日期对象,即将Date转换为yyyy-MM-dd格式
- <fmt:formatDate value="${ abc}" pattern="hh:mma, MM/dd/yyyy" /> jstl 时间data格式
- 时间转换的好用方法(好招1)//Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2007-09-21 11:00:10.0100");
- js扩展Date将时间格式化为"yyyy-MM-dd hh:mm:ss"格式的字符串
- 原生jsDate()时间转换为yyyy-MM-dd 时:分:秒的格式
- struts标签格式化时间<s:date name="neowaveBloodPressure.monitorTime" format="yyyy-MM-dd HH:mm:ss" />
- Json日期格式 转化为 YYYY-MM-DD-hh-mm-ss
- Date( )日期格式Sun Sep 30 00:00:00 CST 2012转换成yyyy-mm-dd
- 将yyyyMMdd HH:mm:ss格式的时间转换成时间类型
- yyyy-MM-dd'T'HH:mm:ss.SSS'Z'即UTC时间,与String日期转换
- java中“dd/MMM/yyyy:HH:mm:ss”转换为格式“yyyy-MM-dd HH:mm:ss”
- JSON 序列化和反序列化:将时间由"//Date(10000000000-0700)//" 格式转换成 "yyyy-MM-dd HH:mm:ss" 格式的字符串
- 写一个方法对日期格式化 new Date().format("yyyy-MM-dd HH:mm:ss")
- [乐意黎原创] 时间格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ 中的T和Z表示什么
- Kettle5.2 couldn't convert string [...] to a date using format [yyyy/MM/dd HH:mm:ss.SSS]
- js中date时间转换yyyy-mm-dd hh:MM:ss等格式字符串
- dd/MM/yyyy:HH:mm:ss +0800时间格式的转换