I am using moment object for date. and for that i wrote
dateOnly = moment(date.format("MM/DD/YYYY"));
var ndate = dateOnly.toDate();
I want to display only date on front end but it is showing me in this format that I don't want
Mon Feb 22 2016 00:00:00 GMT+0530 (India Standard Time)
js parsing date and time. We can parse a string representation of date and time by passing the date and time format to the moment function. const moment = require('moment'); let day = "03/04/2008"; let parsed = moment(day, "DD/MM/YYYY"); console. log(parsed.
moment(). format('YYYY-MM-DD'); Calling moment() gives us the current date and time, while format() converts it to the specified format. This example formats a date as a four-digit year, followed by a hyphen, followed by a two-digit month, another hyphen, and a two-digit day.
var check = moment('date/utc format'); day = check. format('dddd') // => ('Monday' , 'Tuesday' ----) month = check. format('MMMM') // => ('January','February.....) year = check. format('YYYY') // => ('2012','2013' ...)
You can use moment's format function to display date in the format you want to
moment().format('MM/DD/YYYY'); // "02/22/2016"
You can go through all the available formats here
http://momentjs.com/docs/#/displaying/
var dateOnly = moment(date).format('MM/DD/YYYY'); // for formatted dates.
yesterday= moment(date).subtract(1,'days') // for previous day
//you can replace days with months and years.
tomorrow= moment(date).add(1,'days') // for upcoming day
//you can replace days with months and years.
var date1= moment(yesterday)
var date2= moment(tomorrow)
differencebetweenmoments =moment(date1).diff(moment(date2),'days');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With