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.
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.
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
$scope.SearchDate = moment(moment.now()).format("DD/MM/YYYY")
–
Shorten moment()
is the same as moment(new Date())
–
Hooker 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");
This worked for me
var dateToFormat = "2018-05-16 12:57:13"; //TIMESTAMP
moment(dateToFormat).format("DD/MM/YYYY"); // you get "16/05/2018"
This actually worked for me:
moment(mydate).format('L');
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>
A safe way to do this
moment.locale('en-US');
moment().format("L");
"06/23/2021"
moment.locale('fr');
moment().format("L");
"23/06/2021"
The best way is:
let today = new Date();
let todayFormatted = moment(today).format('DD-MM-YYYY');
let startDateFormatted = moment(startDate).format('DD-MM-YYYY');
const isStartDateToday = (todayFormatted === startDateFormatted);
startDate
thing which can be found nowhere in the question, this answer does not have anything new compared to existing answers. –
Dragline © 2022 - 2025 — McMap. All rights reserved.
new Date()
is javascript code. can you give me for get current date by using moment.js? – Prolonge