减去2倍于反应天然

问题描述 投票:0回答:1

我想减去两倍,并检查是否CHECK_IN时间> 12小时,然后导航到签屏幕。这是我的代码片段

 class SplashView extends Component {

    componentDidMount() {
        const curr_time = moment().format('hh:mm:ss');
        const checkin_time = moment(this.props.datetime).format('hh:mm:ss');
        // const diff = moment.duration(checkin_time.diff(curr_time));
        console.log("TIME&&&&&&&&", curr_time, checkin_time);
        setTimeout(() => {
            if (this.props.employee_id === null) {
                this.props.navigation.navigate('Login');
            } else {
                this.props.navigation.navigate('Checkin');
            }

        }, 1000)
    }



    render() {
        return ();
    }
}

我使用moment.js和this.props.datetime值是“2019年2月4日14时52分01秒”。这是我签的时间。

react-native momentjs
1个回答
0
投票

你可以在这样的时间的区别:

const diff = moment.duration(checkin_time.diff(curr_time)).as('hours');

或者,你可以使用瞬间的差异功能

const diff = checkin_time.diff(curr_time, 'hours')

然后比较if (diff > 12) { ... }

© www.soinside.com 2019 - 2024. All rights reserved.