'How to get DD-MM-YYYY format date
I'm using Parse database. I store date format. when using console i get this format : Tue Jul 18 2017 15:46:47 GMT+0100 (CET)
I want to get this format : 18-07-2017.
Any idea please
Solution 1:[1]
It can be done by using following code:
let today = new Date();
let date=today.getDate() + "-"+ parseInt(today.getMonth()+1) +"-"+today.getFullYear();
console.log(date)
Solution 2:[2]
The moment library is awesome for all action/formatting that you want to do on date.
Have a look: https://momentjs.com/
You should do something like this:
import * as moment from 'moment'
const yourDate = new Date()
const NewDate = moment(yourDate, 'DD-MM-YYYY')
Solution 3:[3]
I have been able to get the result that you want in react-native like this:
import moment from 'moment'; // Import momentjs --> https://momentjs.com
const maxDate = moment(new Date, 'DD-MM-YYYY').format(); // 15-11-2017T11:17:30+01:00
I hope this is useful for you.
Solution 4:[4]
This resolved formatted my date into dd/mm/yyyy
import moment from 'moment';
let date = moment(new Date()).format('DD/MM/YYYY')
Solution 5:[5]
import moment from 'moment';
var NewDate= moment(new Date, 'DD-MM-YYYY').format();
NewDate=NewDate.split('T')[0];
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | |
Solution 3 | |
Solution 4 | AMAL MOHAN N |
Solution 5 | AYUSH CHAUDHARY |