// 获取当前时间戳(以s为单位)
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
//当前时间戳为:1403149534
console.log("当前时间戳为:" + timestamp); // 获取某个时间格式的时间戳
var stringTime = "2014-07-10 10:21:12";
var timestamp2 = Date.parse(new Date(stringTime));
timestamp2 = timestamp2 / 1000;
//2014-07-10 10:21:12的时间戳为:1404958872
console.log(stringTime + "的时间戳为:" + timestamp2); // 将当前时间换成时间格式字符串
var timestamp3 = 1403058804;
var newDate = new Date();
newDate.setTime(timestamp3 * 1000);
// Wed Jun 18 2014
console.log(newDate.toDateString());
// Wed, 18 Jun 2014 02:33:24 GMT
console.log(newDate.toGMTString());
// 2014-06-18T02:33:24.000Z
console.log(newDate.toISOString());
// 2014-06-18T02:33:24.000Z
console.log(newDate.toJSON());
// 2014年6月18日
console.log(newDate.toLocaleDateString());
// 2014年6月18日 上午10:33:24
console.log(newDate.toLocaleString());
// 上午10:33:24
console.log(newDate.toLocaleTimeString());
// Wed Jun 18 2014 10:33:24 GMT+0800 (中国标准时间)
console.log(newDate.toString());
// 10:33:24 GMT+0800 (中国标准时间)
console.log(newDate.toTimeString());
// Wed, 18 Jun 2014 02:33:24 GMT
console.log(newDate.toUTCString()); Date.prototype.format = function(format) {
var date = {
"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+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}
console.log(newDate.format('yyyy-MM-dd h:m:s')); </script>

时间戳 js 转换的更多相关文章

  1. 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换

    var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...

  2. js 时间戳 vue 时间戳的转换 ?

    在没有用vue做项目之前 也遇到过戳转换的问题 直接函数 调用 方法 这个也可以写成vue的  把function去掉  formatDate后面加冒号 就可以了 当然这个不是原创 但是是谁的我忘记了 ...

  3. 微信小程序时间戳的转换及调用

    13位 的时间戳,如下图: 效果图: 1.(utils.js里面的代码): function formatTime(timestamp, format) { const formateArr = [' ...

  4. 微信小程序——时间戳的转换及调用

    开发微信小程序网盘功能模块的时候,需要获取到网盘文件夹创建的时间.如下图: 但是请求返回的数据是一段时间戳,如下图: 所以我们只能通过js把时间戳转换成时间格式. 在小程序官网的Demo的utils. ...

  5. JS转换HTML转义符

    JS转换HTML转义符 //去掉html标签 function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,'') ...

  6. java 时间戳和PHP时间戳 的转换

    java 时间戳和PHP时间戳 的转换 PHPJava  总结一下java 时间戳和PHP时间戳 的转换问题: 由于精度不同,导致长度不一致,直接转换错误. JAVA时间戳长度是13位,如:12948 ...

  7. Sublime Text3时间戳查看转换插件的开发

    平常配置表中,经常需要用到时间配置,比如活动开始结束.从可读性上,我们喜欢2017-04-27 17:00:00,从程序角度,我们喜欢用1493283600.前者是包含时区概念的,而后者市区无关,所以 ...

  8. JS 转换HTML转义符

    JS转换HTML转义符   //去掉html标签 1 2 3 function removeHtmlTab(tab) {  return tab.replace(/<[^<>]+?& ...

  9. JS转换HTML转义符,编码及解码

    JS转换HTML转义符 //去掉html标签 function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,'') ...

随机推荐

  1. python解析网页中js动态添加的内容

    https://www.cnblogs.com/asmblog/archive/2013/05/07/3063809.html https://www.zhihu.com/question/21471 ...

  2. 边看chromium的代码,边想骂人...

    这一年一直在看chromium for android的代码,边看边想骂,谷歌这帮人..一开始搞了个牛逼的架构,在安卓4.4上把以前android webkit团队的简单版替换掉了,结果发现性能大不如 ...

  3. 网络编程中的常见陷阱之 0x十六进制数(C++字面值常量)

    十六进制数相等的推断 请问例如以下程序的输出是神马? #include <iostream> #include <string> using namespace std; in ...

  4. easyui datagrid client搜索、分页、排序

    easyui datagrid的排序默认是server端排序.能够用sorter实现client排序[2].client分页可用filter实现[3].client搜索相同能够用filter实现. 不 ...

  5. 微信小程序 项目实战(一)生命周期 配置服务器信息 splash启动页

    步骤一:小程序 生命周期 //app.js App({ onLaunch: function () { //当小程序初始化完成时,会触发onLaunch(全局只触发一次) }, onShow: fun ...

  6. 手机号码归属地查询免费api接口代码

    依据手机号码查询用户的卡类型.运营商.归属地.区域等信息. 手机归属地实体类 package org.wx.xhelper.model; /** * 手机归属地 * @author wangxw * ...

  7. NVIDIA---CUDA

    http://en.wikipedia.org/wiki/CUDA CUDA From Wikipedia, the free encyclopedia     CUDA Developer(s) N ...

  8. jmeter3.0_bodydata中存在中文乱码

    jmeter3.0_bodydata中存在中文乱码 1.进入jmeter.properties配置文件 找到#jsyntaxtextarea.font.family=Hack ,并将“#”取消并重启j ...

  9. HBase2.0新特性之In-Memory Compaction

    In-Memory Compaction是HBase2.0中的重要特性之一,通过在内存中引入LSM结构,减少多余数据,实现降低flush频率和减小写放大的效果.本文根据HBase2.0中相关代码以及社 ...

  10. Dom解析XMl文档

    XMl文档 <?xml version = "1.0" encoding = "UTF-8"?> <books> <book bo ...