Skip to content Skip to sidebar Skip to footer

Dd/mm/yyyy Date Format In Moment.js

How can i change the current date to this format(DD/MM/YYYY) using moment.js? I have tried below code. $scope.SearchDate = moment(new Date(), 'DD/MM/YYYY'); But it's return 0037-1

Solution 1:

You need to call format() function to get the formatted value

$scope.SearchDate = moment(new Date()).format("DD/MM/YYYY")
//or $scope.SearchDate = moment().format("DD/MM/YYYY")

The syntax you have used is used to parse a given string to date object by using the specified formate

Solution 2:

You can use this

moment().format("DD/MM/YYYY");

However, this returns a date string in the specified format for today, not a moment date object. Doing the following will make it a moment date object in the format you want.

var someDateString = moment().format("DD/MM/YYYY");
var someDate = moment(someDateString, "DD/MM/YYYY");

Solution 3:

Solution 4:

This actually worked for me:

moment(mydate).format('L');

Solution 5:

for anyone who's using react-moment:

simply use format prop to your needed format:

const now = newDate()
<Moment format="DD/MM/YYYY">{now}</Moment>

Post a Comment for "Dd/mm/yyyy Date Format In Moment.js"