javascript时间戳和日期字符串相互转换
来源:互联网 发布:淘宝卖家需要用的软件 编辑:程序博客网 时间:2024/06/08 05:42
12345
// 获取当前时间戳(以s为单位)var timestamp = Date.parse(new Date());timestamp = timestamp / 1000;//当前时间戳为:1403149534console.log("当前时间戳为:" + timestamp);
123456
// 获取某个时间格式的时间戳var stringTime = "2014-07-10 10:21:12";var timestamp2 = Date.parse(new Date(stringTime));timestamp2 = timestamp2 / 1000;//2014-07-10 10:21:12的时间戳为:1404958872console.log(stringTime + "的时间戳为:" + timestamp2);
时间戳转日期格式
123456
<script>function getLocalTime(nS) {return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');}alert(getLocalTime(1293072805));</script>
结果是 2010-12-23 10:53
123456
<script>function getLocalTime(nS) {return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");}alert(getLocalTime(1177824835));</script>
结果是 2010年12月23日 10:53
12
console.log(Date.parse(new Date('2017-07-03 23:59:59')) / 1000);//转为时间戳console.log(new Date(parseInt(1499097599) * 1000).toLocaleString());//转为日期
阅读全文
0 0
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换(json)
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- javascript时间戳和日期字符串相互转换
- 使用python进行图片格式转换
- 补充学习:关于数据库的存储过程与函数
- 收银员绩效考核评分表(月度)
- MyBatis+MySQL 返回插入的主键ID
- AngularJs——$http请求数据
- javascript时间戳和日期字符串相互转换
- java算数运算之除法与取余
- MVC和MVP
- JavaScript中map()函数的用法
- flaot类型数据与单个字节相互转换
- 9*9乘法表
- Android_studio和ecilpse
- cs231n assignment1 feature
- C语言的一些误用和知识总结