RN 时间戳
curTime: 1555120690696 //是指从1970.1.1到现在的毫秒(ms)数
时间与时间戳之间的转换
// 获取当前时间戳
var timestamp = Date.parse(new Date());
console.log(timestamp); // 获取某个时间格式的时间戳
var stringTime = "2019-06-10 11:37:00";
var timestamp2 = Date.parse(new Date(stringTime)); // 将当前时间换成时间格式字符串
var newDate = new Date();
newDate.setTime(timestamp);
// Mon Jun 10 2019
console.log(newDate.toDateString());
// Mon, 10 Jun 2019 03:37:42 GMT
console.log(newDate.toGMTString());
// 2019-06-10T03:37:42.000Z
console.log(newDate.toISOString());
// 2019-06-10T03:37:42.000Z
console.log(newDate.toJSON());
// 2019/6 /10
console.log(newDate.toLocaleDateString());
// 2019/6/10 上午11:37:42
console.log(newDate.toLocaleString());
// 上午11:37:42
console.log(newDate.toLocaleTimeString());
// Mon Jun 10 2019 11:37:42 GMT +0800(中国标准时间)
console.log(newDate.toString());
// 11:37:42 GMT + 0800(中国标准时间)
console.log(newDate.toTimeString());
// Mon, 10 Jun 2019 03:37:42 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;
}
// 2019-06-10 11:37:42
console.log(newDate.format('yyyy-MM-dd h:m:s'));
将时间戳转换成日期格式
更多方法可以在这查到 ->http://www.w3school.com.cn/jsref/jsref_obj_date.asp
var date = new Date(时间戳); //获取一个时间对象 date.getFullYear(); // 获取完整的年份(4位,1970)
date.getMonth(); // 获取月份(0-11,0代表1月,用的时候记得加上1)
date.getDate(); // 获取日(1-31)
date.getTime(); // 获取时间(从1970.1.1开始的毫秒数)
date.getHours(); // 获取小时数(0-23)
date.getMinutes(); // 获取分钟数(0-59)
date.getSeconds(); // 获取秒数(0-59) // 需要的格式 yyyy-MM-dd hh:mm:ss
var date = new Date(1398250549490);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
console.log(Y + M + D + h + m + s); // 2019-06-10 11:45:39
将日期格式转换成时间戳
计算时间差
cxk() {
//之前时间
let preTime = 1535710147654;
//当前时间
let nowTime = Date.now();
//间隔
let intervalTime = nowTime - preTime;
// 10min 毫秒数
let tenMinites = 60 * 10 * 1000;
let hour = tenMinites * 6;
let day = 24 * hour; if (preTime > nowTime) {
return '当前时间传递有误,请检查!!!'
}
// 刚刚 (10min之内为刚刚)
if (intervalTime < tenMinites || intervalTime === tenMinites) {
return '刚刚'
}
// 几分钟 (10-60min为几分钟)
if (tenMinites < intervalTime && intervalTime <= hour) {
return `${Math.ceil((intervalTime) / tenMinites * .1)}分钟前`
}
// 几小时 (1-24h为几小时)
if (hour < intervalTime && intervalTime <= day) {
return `${Math.ceil((intervalTime) / (6 * tenMinites))}小时前`
}
// (小于7d几天前)
if (day < intervalTime && intervalTime <= day * 7) {
return `${Math.ceil((intervalTime) / (6 * tenMinites * 24))}天前`
}
// (大于7d为几周前)
if (day * 7 < intervalTime && intervalTime <= day * 35) {
return `${Math.ceil((intervalTime) / (6 * tenMinites * 24 * 7))}周前`
}
// (大于四周为几月前)
if (day * 7 * 5 < intervalTime && intervalTime <= day * 7 * 5 * 11) {
return `${Math.ceil((intervalTime) / (6 * tenMinites * 24 * 30))}月前`
}
// 几年 (其余显示几年前)
if (day * 7 * 5 * 11 < intervalTime) {
return `${Math.ceil((intervalTime) / (6 * tenMinites * 24 * 365))}年前`
}
}
RN 时间戳的更多相关文章
- C# DateTime与时间戳转换
C# DateTime与时间戳的相互转换,包括JavaScript时间戳和Unix的时间戳. 1. 什么是时间戳 首先要清楚JavaScript与Unix的时间戳的区别: JavaScript时间戳: ...
- nodejs中获取时间戳、时间差
Nodejs中获取时间戳的方法有很多种,例如: new Date().getTime() Date.now() process.uptime() process.hrtime() 平时想获取一个时间戳 ...
- 基于RN开发的一款视频配音APP(开源)
在如今React.ng.vue三分天下的格局下,不得不让自己加快学习的脚步.虽然经常会陷入各种迷茫,学得越多会发现不会的东西也被无限放大,不过能用新的技术作出一些小项目小Demo还是会给自己些许自信与 ...
- EF里Guid类型数据的自增长、时间戳和复杂类型的用法
通过前两章Lodging和Destination类的演示,大家肯定基本了解Code First是怎么玩的了,本章继续演示一些很实用的东西.文章的开头提示下:提供的demo为了后面演示效果,前面代码有些 ...
- fmt标签把时间戳格式化日期
jsp页面标签格式化日期 <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %> ...
- MySQL对时间戳的转换处理
开发中很多时候在数据库里都会存储Long类型的时间戳,而时间戳做比对会相对麻烦 我的绝决方案: SELECT FROM_UNIXTIME(LEFT(create_time,10), '%Y-%m-%d ...
- Kafka消息时间戳(kafka message timestamp)
最近碰到了消息时间戳的问题,于是花了一些功夫研究了一下,特此记录一下. Kafka消息的时间戳 在消息中增加了一个时间戳字段和时间戳类型.目前支持的时间戳类型有两种: CreateTime 和 L ...
- Python时间戳和日期的相互转换
Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼ 分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...
- 时间戳TimeStamp处理
我获得这个时间戳是得想除以1000再处理的,看看你们的需要先除多少再处理 //时间戳处理 NSInteger time = timeStamp / 1000; NSNumber *timer = [ ...
随机推荐
- holer实现外网访问内网数据库
外网访问本地数据库 本地安装了数据库,只能在局域网内访问,怎样从公网也能访问内网数据库? 本文将介绍使用holer实现的具体步骤. 1. 准备工作 1.1 安装并启动数据库 默认安装的数据库端口是33 ...
- 爬虫豆瓣top250项目-开发文档
项目托管平台地址:https://github.com/gengwenhao/GetTop250.git 负责内容:1.使用python的request库先获取网页内容下来 2.再使用一个好用的lxm ...
- Python面面面
1:Python有哪些特点和优点? 作为一门编程入门语言,Python主要有以下特点和优点: 可解释 具有动态特性 面向对象 简明简单 开源 具有强大的社区支持 当然,实际上Python的优点远不止如 ...
- ADO.Net中DataSet的应用
一.知识点描述 1.DataSet是ADO.NET的中心概念.可以把DataSet当成内存中的数据库,DataSet是不依赖于数据库的独立数据集合.也就是说,即使断开数据链路,或者关闭数据库,Data ...
- 双网卡绑定一个IP--bond
双网卡绑定一个IP 步骤1:新建/etc/sysconfig/network-scripts/ifcfg-bond0文件 DEVICE=bond0 ONBOOT=yes BOOTPROTO=stati ...
- VScode编辑器使用
快捷键: shift + alt + F 格式化
- 前端自动化构建工具--Gulp&&Webpack
前端构建工具的作用可以认为是对源项目文件或资源进行文件级处理,将文件或资源处理成需要的最佳输出结构和形式. 在处理过程中,我们可以对文件进行模块化引入.依赖分析.资源合并.压缩优化.文件嵌入.路径替换 ...
- Vue基础之初识Vue
Vue特点及优点 小巧,压缩后体积17KB: 渐进式,不需要一口吃成大胖子,一上来就用所有的东西,可以一步一步.有阶段的先吃成小胖子: 数据驱动,双向数据绑定,MVVM模式,详见下一段 指令,例如v- ...
- 不同组的id列表的汇总对比
需求: 三个不同的dfs中存在不同的多个节点id,现在需要求出不同的dfs之间的节点对应关系,比如,哪些节点在某一个dfs,但是不在另一个dfs中 思路: 一. 如果是单纯计算dfs中节点数量,则可以 ...
- Favorite Donut(HDU 5442)最小表示法+二分
题目给出一个字符串,由a~z表示甜度,随字典序增大,字符串首尾相连形成一个圈,要求从一个位置开始字典序最大的字符串,输出位置以及是顺时针还是逆时针表示.顺时针用0表示,逆时针用1表示. 此题只需要查找 ...