日付フォーマットタイムスタンプ変換カウントダウン処理条件判定

32744 ワード

//     
    formatDate(timestamp, formater) {
        let date = new Date();
        date.setTime(parseInt(timestamp));
        formater = (formater != null) ? formater : 'yyyy-MM-dd hh:mm';
        Date.prototype.Format = function (fmt) {
            var o = {
                "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+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
                    (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
            return fmt;
        }
        return date.Format(formater);
    }
//15     
setTime() {
        this.state.getorderArr.map((item) => {
            var intDiff = item.create_date;//     
            var currentTime = new Date().getTime();//    
            var time15 = 15 * 60 * 1000;//    
            var oldTime = intDiff + time15;//    
            var time = (oldTime - currentTime) / 1000;//     
            var timer = null
            timer = setInterval(() => {
                var minute = 0, second = 0;
                if (time > 0) {//    
                    minute = Math.floor(time / 60);
                    second = Math.floor(time % 60);
                    if (minute <= 9) minute = '0' + minute;
                    if (second <= 9) second = '0' + second;
                    time -= 1;
                    item.time = minute + ':' + second
                    this.setState({
                        getorderArr: this.state.getorderArr
                    })
                } else {
                    //        
                    if (item.status == 'c010101') {
                        clearInterval(timer)
                        this._changeStatus(item, "c010110")
                    }
                }
            }, 1000)
        })

    }
バックグラウンドからのミリ秒カウントカウントダウンは24時間です.
Fetch(requestUrl.URL, {
            "wsProductId": this.state.goodsDetailInfo.gb_main_product_id ? this.state.goodsDetailInfo.gb_main_product_id : '',//    id
            "productId": this.state.goodsInfo.gb_product_id,//  id
            "groupId": this.state.goodsInfo.activity_id,//      
            "userId": UserInfo && UserInfo.id ? UserInfo.id : "0",//  ID
        }).then(data => {
            console.log(data);
            this.setState({
                isLoading: false,
            })
            this.setState({
                numIndex: data.data.stock > 0 ? 1 : 0,
                goodsDetailInfo: data.data
            })
            if (data.status == 'SUCCESS') {
                if (data.data.goodsHeaders.length > 0) {
                    data.data.goodsHeaders.map((item) => {
                        var intDiff = item.millis;//     

                        let timer = setInterval(() => {
                            var h = 0, m = 0, s = 0;
                            if (intDiff > 0) {//    
                                h = Math.floor(intDiff % (24 * 3600) / 3600); //  
                                m = Math.floor((intDiff % 3600) / 60); //  
                                s = Math.floor(intDiff % 60); //  
                                if (h <= 9) h = '0' + h;
                                if (m <= 9) m = '0' + m;
                                if (s <= 9) s = '0' + s;
                                intDiff -= 1;
                                item.Date = h + ':' + m + ':' + s
                                this.setState({
                                    goodsDetailInfo: data.data
                                })
                            } else {
                                //        
                                clearInterval(timer)
                            }
                        }, 1000)
                    })
                }

            } else if (data.status == "NONETWORK") {
                this.setState({
                    networkFlag: false,
                    isLoading: false,
                })
            } else {
                ToastShow({ "text": "        " })
            }
        })
条件の判断
払い戻しの状態、アフターサービスの状態、時には全部あるかもしれません.時には一つしかないかもしれません.
	<Text style={styles.commonBomBoxDit}>{
                                                    this.state.myOtherObj.c01010502 && !this.state.myOtherObj.c01010501 ?
                                                        this.state.myOtherObj.c01010502 :
                                                        this.state.myOtherObj.c01010501 && !this.state.myOtherObj.c01010502 ?
                                                            this.state.myOtherObj.c01010501 :
                                                            this.state.myOtherObj.c01010501 && this.state.myOtherObj.c01010502 ?
                                                                Number(this.state.myOtherObj.c01010501) + Number(this.state.myOtherObj.c01010502) : null
                                                }
                                                </Text>