How do I return the date?

Asked

Viewed 46 times

-3

renderItem = ({item}) => {
        return(
            <TouchableWithoutFeedback onPress={()=> this.setState({isItemVisible: true, modalData: {...item}})}>
            <View style={{
                flexDirection: 'row',
                flex: 1,
                marginLeft: 25
            }}>
                <View style={{
                    flex: 1,
                    justifyContent: 'center'
                }}>
                    <Text style={{color: 'black'}}>{item.period}h</Text>
                </View>
                <View style={{flex: 2, marginLeft: 5, justifyContent: 'center'}}>
                    <Text style={{color: 'black', textAlign: 'justify'}}>{item.name}</Text>
                </View>
                <View style={{alignItems: 'flex-end', justifyContent: 'center'}}>
                    <MaterialIcons name='keyboard-arrow-right' size={20} />
                </View>
            </View>
            </TouchableWithoutFeedback>
        )
    }

My item.period comes from the api and I want to return it only the day of the month that is there

  • What is his current value?

  • It returns me the date in HTML

  • I want to know what value is coming in your object. If it’s coming 2019-01-01 11:22:33, or 25/1/2019 00:00:00 PM, etc..

  • "period": "2019-10-17T00:00:00.000-03:00",

1 answer

0


To do straight in rendering you can use so:

<Text style={{color: 'black'}}>{new Date(item.period).getDate()}h</Text>

It will return you the day of the month as you wish, in case the entry is as your example "period": "2019-10-17T00:00:00.000-03:00" will return 17

  • That’s right, thank you

  • @Ruanduarte, since my answer helped you solve your problem, then if you have no further questions, would you please accept it? If there is still any doubt or point to clarify, please tell me so that we can clarify it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.