简体   繁体   中英

Get day from a Date - React Native

in my program when I click on a calendar I am getting the "selectedDate" variable changed. Like if I click on 4/6/2021 the value of selectedDate = 04-06-2021, Like if I click on 14/7/2021 the value of selectedDate = 14-07-2021.

I need to get which day of the week the dates are. I am trying in this way:

        <View>
           
            <H1 color={color.white}>{days[selectedDate.getDay()]}</H1>
          
         </View>

I need to get which day of the week is the selected date. this syntax is giving an error "Property 'getDay' does not exist on type 'string'"

you can use moment( https://momentjs.com/ ) for this. With the help of moment we can get date in different formats. I hope you this will help

Use moment https://momentjs.com/

import moment inside your file

moment().format('dddd');

this is the method to get day from a given date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM