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 = [ ...
随机推荐
- CSS效果:简单的登录框
HTML: <html lang="en"> <head> <meta charset="UTF-8"> <meta ...
- html之跳转锚
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- c语言——单链表分拆——头插法创建链表,尾插法生成链表
#if 1 #include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; ...
- python3学习笔记及常见问题
1,mac自带的python是2.7版本,我们需要按照python3,这样在terminal下可以直接使用,但是编译打包的时候会默认使用python2.7 解决办法:安装virtualenv,一个管理 ...
- 使用vue-cli搭建项目
在使用vue-cli搭建项目前提: 1.node.js环境 2.npm镜像 开始. 1.cmd打开命令行, npm install -g vue-cli 进行全局安装 (vue-V可以查看其版本) ...
- React Native 获取组件(Component)在屏幕上的位置
年后主客户端的需求以及老的业务迁移RN,现在疯狂的在学RN.在迁移需求的时候遇到需要获取组件在屏幕上的绝对位置.页面如下: 就需要展开的时候获取sectionHeader(默认排序)在屏幕上的具体位置 ...
- 数字特征值-python
#Digital eigenvalue.py number = eval(input()) count = 0 Ob = 0 Ox = 0 while number > 0: Ob = numb ...
- AS 400 常用命令
转自:http://blog.chinaunix.net/uid-22375044-id-3049793.html 一.命令技巧 命令构成: CRT* (Creat) 创建 WRK* (Work Wi ...
- HTTP Post multipart/form-data支持
最近需要向平台发送录像文件,但是Skynet没有multipart/form-data的Post请求支持,写篇blog记录一下 skynet有自带简单的httpc,里面有post方法.但是这个post ...
- gulp在项目中的基本使用
在项目中用gulp做项目的代码的管理,用起来很方便.主要用到了下面一些功能 关于js的处理,包括合并.压缩.加hash. 关于css的处理,编辑scss,合并css,加hash,自动加入前缀 本地开发 ...