Hi @usmansagri,
After you fetch the data from the API and convert it into JSON format. You can divide the date string into two separate substrings – date and time.
Please refer to the JS code below:
const datefromapi = data.date;
const indexOf_T = datefromapi.indexOf("T");
const date = datefromapi.substr(0,indexOf_T);
const time = datefromapi.substr(indexOf_T + 1);
I hope this helps.
How can i achieve that in the following code? i have to fetch all the posts and their timestamp!
return(
<View style={styles.container}>
{isLoading ? (<ActivityIndicator />): (
<FlatList
data={catPost}
keyExtractor={({ id },index) => id}
renderItem={({ item }) => (
<TouchableOpacity onPress={() => navigation.navigate('CatPostModal')}>
{item.featured_media>0?<Image style={{width:Dimensions.width,height:250}} source={{
uri: item.imageLink
}}/>:null}
<View style={{padding:5,backgroundColor:'#fff',margin:5}}><Text style={{fontWeight:'bold',color:'#3578e5',fontSize:20,marginTop:5}}>{item.title.rendered}</Text>
<Text style={{color:'#000',marginTop:5}}>{item.date}</Text>
</View>
</TouchableOpacity>
)
}
/>
)}
</View>
)