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
  • 5,884
  • 6
  • 45
  • 50
Julvador
  • 31
  • 1
  • 1
  • 3

1 Answers1

35

You can use this :

var today = new Date();
date=today.getDate() + "/"+ parseInt(today.getMonth()+1) +"/"+ today.getFullYear();
console.log(date);
Saravana Kumar
  • 3,230
  • 7
  • 26
  • 44