简体   繁体   English

使用Json响应对象作为限制日期来响应本机countDown计时器

[英]React Native countDown Timer using a Json response object as a limit date

i'm tring to use countdown timer using a json response as a limit date (Replacing the until={this.state.totalDuration} with until={item.date} ) but i failed i always have NaN NaN NaN . 我正在尝试使用以json响应作为倒数日期的倒数计时器(将直到== {this.state.totalDuration}替换为直到= {item.date}),但是我失败了,我总是NaN NaN NaN。 how ever if i change the until value directly for example (until={'2020-12-12'}) i don't get a NaN NaN NaN in the countdown but i get a count down that goes down from 30 min and that's akward 例如,如何直接更改直到值(直到= {'2020-12-12'}),我在倒计时中没有得到NaN NaN NaN,但是我从30分钟开始倒数了笨拙的

<Content >
     <View style ={{ flex:1}}>
       <FlatList
         data={this.state.data}
         keyExtractor={(item,index) => index.toString()}
         renderItem={({item}) =>
          <View style={{backgroundColor:'#e6e6e6',padding:10,margin:10}}>
            <ListItem icon>
              <Left>
                <Button style={{ backgroundColor: "white" }}>
                  <Icon0 active name="doctor" />
                </Button>
              </Left>
              <Body>
                <Text>Nom du Docteur : Dr. {item.nom}</Text>
              </Body>
            </ListItem>
            <ListItem icon>
              <Left>
                <Button style={{ backgroundColor: "white" }}>
                  <Icon1 active name="calendar" />
                </Button>
              </Left>
              <Body>
                <Text>Date du rendez-vous : {item.date}</Text>
              </Body>
            </ListItem>
            <ListItem icon>
              <Left>
                <Button>
                  <Icon1 active name="calendar"/>
                </Button>
              </Left>
              <Body>
                <CountDown
                  until={item.date}
                  timetoShow={('H', 'M', 'S')}
                  onFinish={() => alert('finished')}
                  onPress={() => alert('hello')}
                  size={10}
                />
            </Body>
          </ListItem>
        </View>
      }
    />
  </View>
</Content>

Edit: * Imports 编辑:*导入

import CountDown from 'react-native-countdown-component';
import moment from 'moment';

问题是,在“ react-native-countdown-component”中,直到使用整数参数(即日期为Seconds),所以您必须将日期转换为seconds。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM