DD/MM/YYYY Date format in Moment.js

后端 未结 5 1135
北恋
北恋 2021-01-31 07:39

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/YYY         


        
相关标签:
5条回答
  • 2021-01-31 08:02

    for anyone who's using react-moment:

    simply use format prop to your needed format:

    const now = new Date()
    <Moment format="DD/MM/YYYY">{now}</Moment>
    
    0 讨论(0)
  • 2021-01-31 08:05

    This worked for me

    var dateToFormat = "2018-05-16 12:57:13"; //TIMESTAMP
    
    moment(dateToFormat).format("DD/MM/YYYY"); // you get "16/05/2018"
    
    0 讨论(0)
  • 2021-01-31 08:12

    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

    0 讨论(0)
  • 2021-01-31 08:12

    This actually worked for me:

    moment(mydate).format('L');
    
    0 讨论(0)
  • 2021-01-31 08:17

    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");
    
    0 讨论(0)
提交回复
热议问题