DD/MM/YYYY Date format in Moment.js

2019-03-11 00:01发布

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-11-24T18:30:00.000Z. Did't help to format current date.

4条回答
地球回转人心会变
2楼-- · 2019-03-11 00:37

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

查看更多
虎瘦雄心在
3楼-- · 2019-03-11 00:41

This actually worked for me:

moment(mydate).format('L');
查看更多
三岁会撩人
4楼-- · 2019-03-11 00:45

This worked for me

var dateToFormat = "2018-05-16 12:57:13"; //TIMESTAMP

moment(dateToFormat).format("DD/MM/YYYY"); // you get "16/05/2018"
查看更多
做自己的国王
5楼-- · 2019-03-11 00:51

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");
查看更多
登录 后发表回答