List of dates in React Native for Today and Tomorrow

In React Native, I am looking to create a dynamic list that displays the next seven days starting from today (assuming today is Monday):

Today - Tomorrow - Wednesday - Thursday - Friday - Saturday - Sunday - Monday
<- My goal is to show a total of seven days.

When a user clicks on any of the items in the list, I want it to return the specific date. For example, clicking on Friday should display 16.07.2021 or any other chosen format.

Thank you for taking the time to read this!

Answer №1

If you need to work with dates in JavaScript, consider using the momentjs library.

Check out their website at https://momentjs.com/

This code snippet demonstrates how you can use momentjs to manipulate dates:

import moment from 'moment'

const returnDates = () => {
    const weekArray = [0,1,2,3,4,5,6]
    const today = new Date()
    return weekArray.map(week => moment(today).add(week, 'days').calendar().split(' at')[0] )
}

This code has been tested and should work as expected.

https://i.sstatic.net/oScda.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Execute an AJAX post request to the identical PHP page (utilizing the Jquery Form Plugin)

I am in the process of developing a new web interface using JavaTMP, an AJAX-based admin template. After spending time understanding its functionality, I have created a page with a form to allow users to create projects within my software. Typically, creat ...

Preventing data overflow when reading into a character array in C++

I am currently working on a program that requires the user to input into char[] arrays of different sizes. I have access to string.h, stdlib.h, and iostream libraries. How can I determine if the user's input exceeds the maximum size minus one (to leav ...

How to retrieve the clicked value using jQuery within a jinja2 loop

I'm currently working on an app that utilizes a Flask backend and Jinja2 templating. Within the HTML, I have a loop set up to organize data into batches, creating three columns on the web page: {% for batch in df.iterrows() | batch(3) %} <d ...

The object in React state is not being refreshed

In the following code snippet, I have a static object with three values. I created a form to take user input and then attempted to merge that new input with the existing static object. However, it does not seem to be working as expected. When I check the ...

Defining the Content-Type for the getAllEntities API in JHipster

I am using a Swagger API to request information on all developers, with the Response Content Type specified as "application/json". The data I receive for developer entities is as follows: [ Developer{id=1001, name='David L. Whitehurst'}, De ...

Fill the dropdown menu with JSON keys

My challenge involves working with an array containing objects, which are sent to the client via a node.js server integrated with mongodb. I need to extract all keys/fields from the object (such as name, surname, telephone) without their values (for exampl ...

Signs that indicate you have reached the bottom of the page

Wondering how they achieve that cool effect on where the top line appears with a new logo when you scroll down? Is it done using a jQuery trick? How can you determine when a person has scrolled down a certain amount of pixels and then show them new HTML ...

Exploring Nested Divs with Vue Test Utils

Recently, I came across this shallowMounted vue component: <div class="card p-relative"> <div class="card-header"> <div class="card-title h4"> a lovely title <!----> <!----> </div> </div ...

How to utilize Vue.js method to retrieve child prop?

In my Vue.js project, I have created two components. The main component uses a child component called NoteRenderer, which includes a prop named data_exchange. My goal is to update this prop from the main component when a button is clicked. I attempted to a ...

Automated vertical alignment of rows within the Bootstrap table

I'm currently working on a table for my personal project that populates with data from the database. I am trying to get the rows to display vertically under headings (see screenshot at the bottom of this question). I have attempted various solutions f ...

Can you guide me on setting a background image URL for rails using javascript?

Within my Rails application, I have a collection of content paired with image buttons (each piece of content has an associated image). When a user clicks on one of these buttons, my goal is to display the corresponding image. All of my images are stored u ...

What is the method for inputting multi-line strings in the REST Client extension for Visual Studio Code?

Clarification There seems to be some confusion regarding the nature of the data I am storing. I am developing a code snippet web application using Express.js and MongoDB. The purpose is not to store executable code for later use; instead, I am saving snipp ...

Don't forget to keep track of when the user has closed

How can I ensure that the cache retains the user's action of closing the div? Currently, when I close the div and refresh the page, it reverts back to its original state. Is there a way to make this change persistent? Experience it live: Here is the ...

Is there a way for me to replicate the reloading problem that occurs when a button is clicked within an HTML

Recently, I encountered a problem with our company's Web product where pressing a certain button resulted in the entire page being reloaded. This issue reminded me of a similar situation described on this website. Following the solution provided there ...

WebWorker tends to be loaded intermittently on android devices

We have integrated a web worker in our Ionic application to handle certain computations. Previously, this setup functioned properly without any issues. However, suddenly we are encountering some challenges. Despite making significant changes throughout th ...

How to rotate text direction using JavaScript and CSS

Despite my extensive efforts, I have been unable to find a solution to a seemingly simple problem. In JavaScript, I have generated dynamic text using the following code: context.fillText('name', 10, 10, 20); Now, I need this text to be ori ...

Unlocking the Power of refs in React's this.props.children

Wondering if it's possible to call a function of a child component in React by accessing refs from this.props.children. var ComponentSection = React.createClass({ componentDidMount: function() { // Need to find a way to access refs in this ...

Ways to resolve the issue of a website displaying with extra whitespace at the bottom

Seeking assistance to resolve the issue with a blank space at the bottom of the web page. Refer to: http://www.khohanghoa.com I have dedicated the entire day to search for a solution and attempted to fix the problem. I have attempted to configure the CS ...

Choose specific columns from distinct tables and arrange them accordingly

I am facing a challenge with my MySQL database as it contains multiple tables with similar columns, and I want to import this data into a Google spreadsheet. For instance: table1 has id, name, page, and other specific columns. table2 also includes id, n ...

Using three.js inside Colab

Here are some examples showcasing bi-directional communications between Python and JavaScript in Google Colab: I'm trying to get this simple three.js demo to work in Colab. Any tips? Despite the seemingly straightforward source code, I'm facing ...