Hello Friends 👋,
Welcome To Infinitbility! ❤️
To get the current year in react native has the new Date().getFullYear()
method which will return every time the current year in number datatype.
we have to just call new Date().getFullYear()
and it will check the current date and return the current year based on the date.
1let year = new Date().getFullYear();2console.log(year); // 2022
Now, we know how to get the current year 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 getFullYear()
method which will return the year store in the new date object.
Let see how we can do in react native
1import * as React from 'react';2import { Text, View, StyleSheet } from 'react-native';34export default function App() {5 return (6 <View style={styles.container}>7 <Text style={styles.paragraph}>{new Date().getFullYear()}</Text>8 </View>9 );10}1112const 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

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.