• Hi

    i am using wordpress api to fetch blog posts from i want to know how can i modify “date” proper date only or how can i seperate date and time from “date”

    • This topic was modified 4 years, 8 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    Thread Starter usmansagri

    (@usmansagri)

    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>
        )
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Modify date object’ is closed to new replies.