使用Json响应对象作为限制日期的React Native countDown Timer

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

我想使用倒数计时器作为限制日期使用倒数计时器(用until直到= {item.date}替换until = {this.state.totalDuration})但是我失败了我总是有​​NaN NaN NaN。如果我直接更改直到值,例如(直到= {'2020-12-12'})我没有在倒计时获得NaN NaN NaN但是我得到倒计时从30分钟开始下降,那是akward的

<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>

编辑:*进口

import CountDown from 'react-native-countdown-component';
import moment from 'moment';
javascript react-native countdown
1个回答
0
投票

问题是在'react-native-countdown-component'中,until采用一个整数参数,即日期为Seconds,因此您必须将日期转换为秒。

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