Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get DD-MM-YYYY format date

Tags:

react-native

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

like image 809
sihem hcine Avatar asked Nov 29 '22 22:11

sihem hcine


2 Answers

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)
like image 194
sai reddy Avatar answered Dec 04 '22 13:12

sai reddy


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')
like image 42
Charles-olivier Demers Avatar answered Dec 04 '22 14:12

Charles-olivier Demers