JS 时间字符串与时间戳之间的转换
2016-12-16 12:55
639 查看
javascript 时间戳 24 小时转换
标签:
1、当前时间换时间戳
2、当前时间换日期字符串
3、日期字符串转时间戳
4、时间戳转日期字符串
var timeTrans = new Date(parseInt(1459408942) * 1000); console.log(timeTrans.toLocaleString('chinese',{hour12:false}));
标签:
1、当前时间换时间戳
var timestamp = parseInt(new Date().getTime()/1000); // 当前时间戳 document.write(timestamp);
2、当前时间换日期字符串
var now = new Date(); var yy = now.getFullYear(); //年 var mm = now.getMonth() + 1; //月 var dd = now.getDate(); //日 var hh = now.getHours(); //时 var ii = now.getMinutes(); //分 var ss = now.getSeconds(); //秒 var clock = yy + "-"; if(mm < 10) clock += "0"; clock += mm + "-"; if(dd < 10) clock += "0"; clock += dd + " "; if(hh < 10) clock += "0"; clock += hh + ":"; if (ii < 10) clock += ‘0‘; clock += ii + ":"; if (ss < 10) clock += ‘0‘; clock += ss; document.write(clock); //获取当前日期
3、日期字符串转时间戳
var date = ‘2015-03-05 17:59:00.0‘; date = date.substring(0,19); date = date.replace(/-/g,‘/‘); var timestamp = new Date(date).getTime(); document.write(timestamp);
4、时间戳转日期字符串
var timestamp = ‘1425553097‘; var d = new Date(timestamp * 1000); //根据时间戳生成的时间对象 var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate()) + " " + (d.getHours()) + ":" + (d.getMinutes()) + ":" + (d.getSeconds()); document.write(date);
相关文章推荐
- js时间加减与时间对象与字符串之间的转换
- js时间加减与时间对象与字符串之间的转换
- js时间戳对象和标准格式字符串之间的转换方法
- js时间加减与时间对象与字符串之间的转换
- js获取时间和日期,字符串和时间戳之间的转换
- js获取时间并实现字符串和时间戳之间的转换
- js获取时间并实现字符串和时间戳之间的转换
- JS 时间字符串与时间戳之间的转换
- js获取时间并实现字符串和时间戳之间的转换
- js获取一天的开始时间和结束时间和日期与字符串、数值之间的转换
- js时间加减与时间对象与字符串之间的转换
- js动态获取当前系统时间+js字符串转换为date日期对象
- 时间戳和字符串之间的互相转换
- JS中json 字符串与对象之间的转换
- js转换json格式时间成字符串前台显示
- JS 时间戳 时间字符串 时间类型相互转换
- Python的时间:秒和字符串之间的转换
- Android 获取当前系统时间 时间之间的转换 判断字符串是否日日期类型
- java 时间与字符串之间的转换 .
- JS 时间字符串转换成时间