Navigate back to the homepage

How to get current month in react native?

Infinitbility
React Native
February 14th, 2022 · 1 min read
keep affilitate

Hello Friends 👋,

Welcome To Infinitbility! ❤️

To get the current month in react native has the new Date().getMonth() method which will return every time the current month index in number datatype.

we have to just call new Date().getMonth() and it will check the current date and return month index based on the date.

1let monthIndex = new Date().getMonth();
2console.log(monthIndex); // 1 for Feb, 0 for jan

So whenever we have to so month number we have to add 1 in got value from new Date().getMonth().

1let monthIndex = (new Date().getMonth() + 1);
2console.log(monthIndex); // 1 for Jan, 2 for Feb

Now, we know how to get the current month in react native and the way to hold in a variable.

React Native has a new Date() object which is similar to javascript and the date object provides the getMonth() method which will return the month index store in the new date object.

Let’s see how we can do it in react native

1import * as React from 'react';
2import { Text, View, StyleSheet } from 'react-native';
3
4export default function App() {
5 return (
6 <View style={styles.container}>
7 <Text style={styles.paragraph}>{`current month is ${new Date().getMonth() + 1}`}</Text>
8 </View>
9 );
10}
11
12const styles = StyleSheet.create({
13 container: {
14 flex: 1,
15 justifyContent: 'center',
16 backgroundColor: '#ecf0f1',
17 padding: 8,
18 },
19 paragraph: {
20 margin: 24,
21 fontSize: 18,
22 fontWeight: 'bold',
23 textAlign: 'center',
24 },
25});

Output

React Native, current, month, example
React Native, get current month example.
  • Try it yourself

Thanks for reading…

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to get current year in react native?

React Native, get current year example.

February 14th, 2022 · 1 min read

How to get array from json object in react native?

React Native, get array from object example.

February 13th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]