180916-ReactJs之日期转换

常见的日期与时间戳之间的相互转换,记录下借助插件momoent来实现

1. 使用姿势

使用前,有那么几步需要走

安装依赖

1
sudo npm install --save moment

引入依赖

1
import moment from 'moment';

开始使用

1
2
// 将时间戳(ms),转换为指定格式的日期
moment(Time).format("YYYY-MM-DD HH:mm:ss")

2. 常用说明

a. 日期格式化

1
2
3
4
5
moment().format('MMMM Do YYYY, h:mm:ss a'); // 九月 16日 2018, 8:54:12 晚上
moment().format('dddd'); // 星期日
moment().format("MMM Do YY"); // 9月 16日 18
moment().format('YYYY [escaped] YYYY'); // 2018 escaped 2018
moment().format(); // 2018-09-16T20:54:12+08:00

b. 相对时间

1
2
3
4
5
moment("20111031", "YYYYMMDD").fromNow(); // 7 年前
moment("20120620", "YYYYMMDD").fromNow(); // 6 年前
moment().startOf('day').fromNow(); // 21 小时前
moment().endOf('day').fromNow(); // 3 小时内
moment().startOf('hour').fromNow(); // 1 小时前

c. 日历时间

1
2
3
4
5
6
7
8
moment().subtract(10, 'days').calendar(); // 2018年9月6日
moment().subtract(6, 'days').calendar(); // 本周一晚上8点55
moment().subtract(3, 'days').calendar(); // 本周四晚上8点55
moment().subtract(1, 'days').calendar(); // 昨天晚上8点55分
moment().calendar(); // 今天晚上8点55分
moment().add(1, 'days').calendar(); // 明天晚上8点55分
moment().add(3, 'days').calendar(); // 下周三晚上8点55
moment().add(10, 'days').calendar(); // 2018年9月26日

d. 多语言

1
2
3
4
5
6
7
8
moment().format('L');    // 2018-09-16
moment().format('l'); // 2018-09-16
moment().format('LL'); // 2018年9月16日
moment().format('ll'); // 2018年9月16日
moment().format('LLL'); // 2018年9月16日晚上8点55分
moment().format('lll'); // 2018年9月16日晚上8点55分
moment().format('LLLL'); // 2018年9月16日星期日晚上8点55分
moment().format('llll'); // 2018年9月16日星期日晚上8点55分

II. 其他

0. 相关

1. 一灰灰Bloghttps://liuyueyi.github.io/hexblog

一灰灰的个人博客,记录所有学习和工作中的博文,欢迎大家前去逛逛

2. 声明

尽信书则不如,已上内容,纯属一家之言,因个人能力有限,难免有疏漏和错误之处,如发现bug或者有更好的建议,欢迎批评指正,不吝感激

3. 扫描关注

一灰灰blog

QrCode

知识星球

goals

180915-ReactJs之Fix:uncaught at check call argument [object Promise] is not a function

Fix uncaught at check call: argument [object Promise] is not a function

在使用ANTD的魔板套前端页面的时候,遇到了一个诡异的问题,记录下

在modal中的写法如下

1
2
3
4
* addGroup({payload}, {call, put}) {
yield call(addGroup(payload));
console.log("add group over!");
},

在执行时,控制台报错

1
uncaught at check call: argument [object Promise] is not a function

主要原因在 yield call(addGroup(payload)); 的使用姿势问题,对于需要传递参数的去哪个,不能直接这么干,应该改为

1
yield call(addGroup, payload);

II. 其他

1. 一灰灰Bloghttps://liuyueyi.github.io/hexblog

一灰灰的个人博客,记录所有学习和工作中的博文,欢迎大家前去逛逛

2. 声明

尽信书则不如,已上内容,纯属一家之言,因个人能力有限,难免有疏漏和错误之处,如发现bug或者有更好的建议,欢迎批评指正,不吝感激

3. 扫描关注

一灰灰blog

QrCode

知识星球

goals

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×