Home > Back-end >  Create specific time range in react native
Create specific time range in react native

Time:02-20

I am new with react native and I want to display a component with a specific time range only. This is what i did so far

var timerange = new Date()
return(
  <View>
  {timerange.getHour() === 8}
   <Text>display</Text>
  </View>
)

So, if you can see that I display the text in exactly 8 o'clock. I want it to be precisely display at 8 to 16. How do I solve this?

CodePudding user response:

Just use an inline conditional as follows.

var current = new Date()

return (
    {(current.getHours() >= 8 && current.getHours() <= 16) && <Text>It is between 8 and 16 o`clock</Text>}
)
  • Related