3

I'm trying to get the current day/month/year in an Android App in react-native.

This is what i've done:

currentDay: new Date(),
...
console.log('Date:'+this.state.currentDay ,);
console.log('Day: '+this.state.currentDay.getDay() , 'Month: ' + this.state.currentDay.getMonth(), 'Year :'+ this.state.currentDay.getYear());

And in the console I have:

Date:Fri Jun 16 2017 11:27:36 GMT+0000 (GMT)
'Day: 5', 'Month: 5', 'Year :117'

As you see, getDay(), getMonth() and getYear() don't return what I want...

François Maturel
6,1806 gold badges47 silver badges51 bronze badges
asked Jun 16, 2017 at 13:37
1
  • You probably want .getFullYear() instead of .getYear() Commented Jun 16, 2017 at 13:46

1 Answer 1

35

You can use this :

var today = new Date();
date=today.getDate() + "/"+ parseInt(today.getMonth()+1) +"/"+ today.getFullYear();
console.log(date);
answered Jun 16, 2017 at 13:45
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, thank you, it's working well!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.