日期格式化 时间戳转换 倒计时处理 条件判断

//日期格式化
    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>

你可能感兴趣的:(Javascript)