Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create specific time range in react native

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>}
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading