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
Julvador
311 gold badge1 silver badge3 bronze badges
1 Answer 1
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
Saravana Kumar
3,4067 gold badges28 silver badges44 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Julvador
Ok, thank you, it's working well!
default
.getFullYear()instead of.getYear()