Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove time from date with Moment.js?

formatCalendarDate = function (dateTime) {     return moment.utc(dateTime).format('LLL'); }; 

It displays: "28 februari 2013 09:24"

But I would like to remove the time at the end. How can I do that?

I'm using Moment.js.

like image 533
Obsivus Avatar asked Feb 28 '13 08:02

Obsivus


People also ask

How do I remove time from date in moment?

We can remove the time portion from a date with the startOf method. We pass in a date with the hour and minutes set into the moment function. Then we call startOf with the 'day' argument to get return a moment object with the time set to midnight of the same date.

How do I remove time part from JavaScript date?

Use the toDateString() method to remove the time from a date, e.g. new Date(date. toDateString()) . The method returns only the date portion of a Date object, so passing the result to the Date() constructor would remove the time from the date.

How do I format the date and time with moment JS?

Format the date and time with Moment.js. One of the major strengths that Moment.js has over native JavaScript Date objects is how easy it is to format the output date and time. Just chain the format () method to a Moment date object and pass it a format string as a parameter:

What is moment JS and how to use it?

Moment.js is a Swiss Army knife for working with dates in JavaScript. It allows you to parse, validate, manipulate, and display dates and times using a clean and concise API. In this article I’ll show you how to get up and running with Moment.js, as well as demonstrate several of its common use cases.

How to get date and time from a timestamp in moment?

Get a date and time from a timestamp with Moment.js Similar to new Date (ms), you can pass the number of milliseconds since the epoch to moment (): const dayAfterEpoch = moment (86400000); If you want to get a date using a Unix timestamp in seconds, you can use the unix () method:

How to truncate a JavaScript date object to a time?

For people interesting in truncating a Javascript Date object (as in the question title): var d = new Date (); var startOfDay = new Date (d.getFullYear (), d.getMonth (), d.getDate ()); Moreover, the duplicate is definitely not the same question as it is about Moment.js. gives: Thu Jul 11 2019 00:00:00 GMT-0400 (Eastern Daylight Time)


1 Answers

Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:

.startOf('day') 

Ref: http://momentjs.com/docs/#/manipulating/start-of/

like image 173
Graham Charles Avatar answered Oct 14 '22 02:10

Graham Charles