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.
javascript date momentjs
add a comment |
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.
javascript date momentjs
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28
add a comment |
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.
javascript date momentjs
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.
javascript date momentjs
javascript date momentjs
edited May 23 '17 at 8:11
Pang
6,8921563101
6,8921563101
asked Feb 28 '13 at 8:25
ObsivusObsivus
3,388103990
3,388103990
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28
add a comment |
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28
add a comment |
10 Answers
10
active
oldest
votes
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/
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applyingstartOf('day')
, which was then the start of the previous day. Fixed withmoment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is usingformat('LL')
, as have been answered in this thread.
– Sudarshan_SMD
Dec 13 '16 at 7:18
2
To avoid mutating the original object, usesomeMoment.clone().startOf('day')
ormoment(someMoment).startOf('day')
.
– Pang
May 23 '17 at 8:06
|
show 3 more comments
Use format('LL')
Depending on what you're trying to do with it, format('LL')
could do the trick. It produces something like this:
Moment().format('LL'); // => April 29, 2016
add a comment |
The correct way would be to specify the input as per your requirement which will give you more flexibility.
The present definition includes the following
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY h:mm A',
LLLL : 'dddd, MMMM D, YYYY h:mm A'
You can use any of these or change the input passed into moment().format().
For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY')
.
add a comment |
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
With newer versions of moment.js you can also do this:
var dateTime = moment();
var dateValue = moment({
year: dateTime.year(),
month: dateTime.month(),
day: dateTime.date()
});
See: http://momentjs.com/docs/#/parsing/object/.
Wouldn't it bedate: dateTime.date()
instead ofday: dateTime.date()
?
– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.day
works pre version 2.8.4.
– oldwizard
May 17 '17 at 7:13
add a comment |
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
You can use this constructor
moment({h:0, m:0, s:0, ms:0})
http://momentjs.com/docs/#/parsing/object/
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Add some ore description here
– Billa
Aug 23 '18 at 12:45
add a comment |
Try this:
moment.format().split("T")[0]
Watch out with this method, as1993-06-07T22:00:00.000Z
will result as1993-06-07
whereas it is the start of the day of1993-06-08
– Tom
Nov 20 '17 at 7:49
add a comment |
Whenever I use the moment.js
library I specify the desired format this way:
moment(<your Date goes here>).format("DD-MMM-YYYY")
or
moment(<your Date goes here>).format("DD/MMM/YYYY")
... etc I hope you get the idea
Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L
,LL
, etc.)
– AJ Richardson
Apr 2 '18 at 21:46
add a comment |
For people like me want the long date format (LLLL
) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:
var localeData = moment.localeData( moment.locale() ),
llll = localeData.longDateFormat( 'llll' ),
lll = localeData.longDateFormat( 'lll' ),
ll = localeData.longDateFormat( 'll' ),
longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
var formattedDate = myMoment.format(longDateFormat);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15130735%2fhow-can-i-remove-time-from-date-with-moment-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
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/
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applyingstartOf('day')
, which was then the start of the previous day. Fixed withmoment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is usingformat('LL')
, as have been answered in this thread.
– Sudarshan_SMD
Dec 13 '16 at 7:18
2
To avoid mutating the original object, usesomeMoment.clone().startOf('day')
ormoment(someMoment).startOf('day')
.
– Pang
May 23 '17 at 8:06
|
show 3 more comments
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/
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applyingstartOf('day')
, which was then the start of the previous day. Fixed withmoment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is usingformat('LL')
, as have been answered in this thread.
– Sudarshan_SMD
Dec 13 '16 at 7:18
2
To avoid mutating the original object, usesomeMoment.clone().startOf('day')
ormoment(someMoment).startOf('day')
.
– Pang
May 23 '17 at 8:06
|
show 3 more comments
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/
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/
edited Nov 26 '18 at 16:18
trojek
676730
676730
answered Oct 31 '13 at 6:03
Graham CharlesGraham Charles
5,52132035
5,52132035
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applyingstartOf('day')
, which was then the start of the previous day. Fixed withmoment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is usingformat('LL')
, as have been answered in this thread.
– Sudarshan_SMD
Dec 13 '16 at 7:18
2
To avoid mutating the original object, usesomeMoment.clone().startOf('day')
ormoment(someMoment).startOf('day')
.
– Pang
May 23 '17 at 8:06
|
show 3 more comments
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applyingstartOf('day')
, which was then the start of the previous day. Fixed withmoment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is usingformat('LL')
, as have been answered in this thread.
– Sudarshan_SMD
Dec 13 '16 at 7:18
2
To avoid mutating the original object, usesomeMoment.clone().startOf('day')
ormoment(someMoment).startOf('day')
.
– Pang
May 23 '17 at 8:06
66
66
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying
startOf('day')
, which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
Be careful with this if you're going between timezones (or if you're not paying attention to timezones). I had an issue where my UTC date was getting converted to local time, then applying
startOf('day')
, which was then the start of the previous day. Fixed with moment(moment.utc('2013-10-29T00:00:00+00:00').startOf('day').format('LL')).startOf('day').toDate()
– colllin
Nov 6 '13 at 5:37
6
6
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
This should definetly be the accepted answer
– Luca Steeb
Apr 23 '15 at 20:03
19
19
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
Also be careful that this function actually mutates the original object
– Dirk Boer
Jul 8 '15 at 16:36
4
4
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL')
, as have been answered in this thread.– Sudarshan_SMD
Dec 13 '16 at 7:18
.startOf('day')
does not removes the time part per se, it just sets the time to 00:00:00. So, yes, as commented by 'collin', you have to be careful when saving date. Better alternative is using format('LL')
, as have been answered in this thread.– Sudarshan_SMD
Dec 13 '16 at 7:18
2
2
To avoid mutating the original object, use
someMoment.clone().startOf('day')
or moment(someMoment).startOf('day')
.– Pang
May 23 '17 at 8:06
To avoid mutating the original object, use
someMoment.clone().startOf('day')
or moment(someMoment).startOf('day')
.– Pang
May 23 '17 at 8:06
|
show 3 more comments
Use format('LL')
Depending on what you're trying to do with it, format('LL')
could do the trick. It produces something like this:
Moment().format('LL'); // => April 29, 2016
add a comment |
Use format('LL')
Depending on what you're trying to do with it, format('LL')
could do the trick. It produces something like this:
Moment().format('LL'); // => April 29, 2016
add a comment |
Use format('LL')
Depending on what you're trying to do with it, format('LL')
could do the trick. It produces something like this:
Moment().format('LL'); // => April 29, 2016
Use format('LL')
Depending on what you're trying to do with it, format('LL')
could do the trick. It produces something like this:
Moment().format('LL'); // => April 29, 2016
edited May 21 '18 at 16:53
answered Apr 30 '16 at 0:52
Joshua PinterJoshua Pinter
24k8138165
24k8138165
add a comment |
add a comment |
The correct way would be to specify the input as per your requirement which will give you more flexibility.
The present definition includes the following
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY h:mm A',
LLLL : 'dddd, MMMM D, YYYY h:mm A'
You can use any of these or change the input passed into moment().format().
For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY')
.
add a comment |
The correct way would be to specify the input as per your requirement which will give you more flexibility.
The present definition includes the following
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY h:mm A',
LLLL : 'dddd, MMMM D, YYYY h:mm A'
You can use any of these or change the input passed into moment().format().
For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY')
.
add a comment |
The correct way would be to specify the input as per your requirement which will give you more flexibility.
The present definition includes the following
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY h:mm A',
LLLL : 'dddd, MMMM D, YYYY h:mm A'
You can use any of these or change the input passed into moment().format().
For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY')
.
The correct way would be to specify the input as per your requirement which will give you more flexibility.
The present definition includes the following
LTS : 'h:mm:ss A',
LT : 'h:mm A',
L : 'MM/DD/YYYY',
LL : 'MMMM D, YYYY',
LLL : 'MMMM D, YYYY h:mm A',
LLLL : 'dddd, MMMM D, YYYY h:mm A'
You can use any of these or change the input passed into moment().format().
For example, for your case you can pass moment.utc(dateTime).format('MMMM D, YYYY')
.
answered Mar 1 '17 at 17:07
Sahil JainSahil Jain
7061614
7061614
add a comment |
add a comment |
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
edited May 23 '17 at 8:13
Pang
6,8921563101
6,8921563101
answered Feb 28 '13 at 8:31
AmGatesAmGates
1,6781326
1,6781326
add a comment |
add a comment |
With newer versions of moment.js you can also do this:
var dateTime = moment();
var dateValue = moment({
year: dateTime.year(),
month: dateTime.month(),
day: dateTime.date()
});
See: http://momentjs.com/docs/#/parsing/object/.
Wouldn't it bedate: dateTime.date()
instead ofday: dateTime.date()
?
– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.day
works pre version 2.8.4.
– oldwizard
May 17 '17 at 7:13
add a comment |
With newer versions of moment.js you can also do this:
var dateTime = moment();
var dateValue = moment({
year: dateTime.year(),
month: dateTime.month(),
day: dateTime.date()
});
See: http://momentjs.com/docs/#/parsing/object/.
Wouldn't it bedate: dateTime.date()
instead ofday: dateTime.date()
?
– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.day
works pre version 2.8.4.
– oldwizard
May 17 '17 at 7:13
add a comment |
With newer versions of moment.js you can also do this:
var dateTime = moment();
var dateValue = moment({
year: dateTime.year(),
month: dateTime.month(),
day: dateTime.date()
});
See: http://momentjs.com/docs/#/parsing/object/.
With newer versions of moment.js you can also do this:
var dateTime = moment();
var dateValue = moment({
year: dateTime.year(),
month: dateTime.month(),
day: dateTime.date()
});
See: http://momentjs.com/docs/#/parsing/object/.
edited Feb 2 '18 at 17:59
FlavorScape
4,99665493
4,99665493
answered Sep 10 '15 at 16:52
Torben Rahbek KochTorben Rahbek Koch
582314
582314
Wouldn't it bedate: dateTime.date()
instead ofday: dateTime.date()
?
– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.day
works pre version 2.8.4.
– oldwizard
May 17 '17 at 7:13
add a comment |
Wouldn't it bedate: dateTime.date()
instead ofday: dateTime.date()
?
– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.day
works pre version 2.8.4.
– oldwizard
May 17 '17 at 7:13
Wouldn't it be
date: dateTime.date()
instead of day: dateTime.date()
?– philfreo
Oct 26 '16 at 18:44
Wouldn't it be
date: dateTime.date()
instead of day: dateTime.date()
?– philfreo
Oct 26 '16 at 18:44
'day and date key both mean day-of-the-month.' from the docs.
day
works pre version 2.8.4.– oldwizard
May 17 '17 at 7:13
'day and date key both mean day-of-the-month.' from the docs.
day
works pre version 2.8.4.– oldwizard
May 17 '17 at 7:13
add a comment |
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
answered Jan 4 '17 at 7:54
Hashmita RautHashmita Raut
416
416
add a comment |
add a comment |
You can use this constructor
moment({h:0, m:0, s:0, ms:0})
http://momentjs.com/docs/#/parsing/object/
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Add some ore description here
– Billa
Aug 23 '18 at 12:45
add a comment |
You can use this constructor
moment({h:0, m:0, s:0, ms:0})
http://momentjs.com/docs/#/parsing/object/
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Add some ore description here
– Billa
Aug 23 '18 at 12:45
add a comment |
You can use this constructor
moment({h:0, m:0, s:0, ms:0})
http://momentjs.com/docs/#/parsing/object/
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
You can use this constructor
moment({h:0, m:0, s:0, ms:0})
http://momentjs.com/docs/#/parsing/object/
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
edited Nov 21 '18 at 22:34
answered Aug 23 '18 at 12:29
EquaProEquaPro
2044
2044
Add some ore description here
– Billa
Aug 23 '18 at 12:45
add a comment |
Add some ore description here
– Billa
Aug 23 '18 at 12:45
Add some ore description here
– Billa
Aug 23 '18 at 12:45
Add some ore description here
– Billa
Aug 23 '18 at 12:45
add a comment |
Try this:
moment.format().split("T")[0]
Watch out with this method, as1993-06-07T22:00:00.000Z
will result as1993-06-07
whereas it is the start of the day of1993-06-08
– Tom
Nov 20 '17 at 7:49
add a comment |
Try this:
moment.format().split("T")[0]
Watch out with this method, as1993-06-07T22:00:00.000Z
will result as1993-06-07
whereas it is the start of the day of1993-06-08
– Tom
Nov 20 '17 at 7:49
add a comment |
Try this:
moment.format().split("T")[0]
Try this:
moment.format().split("T")[0]
edited Aug 28 '17 at 23:19
Moe A
3,75371227
3,75371227
answered Aug 28 '17 at 22:59
Keith BlanchardKeith Blanchard
111
111
Watch out with this method, as1993-06-07T22:00:00.000Z
will result as1993-06-07
whereas it is the start of the day of1993-06-08
– Tom
Nov 20 '17 at 7:49
add a comment |
Watch out with this method, as1993-06-07T22:00:00.000Z
will result as1993-06-07
whereas it is the start of the day of1993-06-08
– Tom
Nov 20 '17 at 7:49
Watch out with this method, as
1993-06-07T22:00:00.000Z
will result as 1993-06-07
whereas it is the start of the day of 1993-06-08
– Tom
Nov 20 '17 at 7:49
Watch out with this method, as
1993-06-07T22:00:00.000Z
will result as 1993-06-07
whereas it is the start of the day of 1993-06-08
– Tom
Nov 20 '17 at 7:49
add a comment |
Whenever I use the moment.js
library I specify the desired format this way:
moment(<your Date goes here>).format("DD-MMM-YYYY")
or
moment(<your Date goes here>).format("DD/MMM/YYYY")
... etc I hope you get the idea
Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L
,LL
, etc.)
– AJ Richardson
Apr 2 '18 at 21:46
add a comment |
Whenever I use the moment.js
library I specify the desired format this way:
moment(<your Date goes here>).format("DD-MMM-YYYY")
or
moment(<your Date goes here>).format("DD/MMM/YYYY")
... etc I hope you get the idea
Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L
,LL
, etc.)
– AJ Richardson
Apr 2 '18 at 21:46
add a comment |
Whenever I use the moment.js
library I specify the desired format this way:
moment(<your Date goes here>).format("DD-MMM-YYYY")
or
moment(<your Date goes here>).format("DD/MMM/YYYY")
... etc I hope you get the idea
Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds
Whenever I use the moment.js
library I specify the desired format this way:
moment(<your Date goes here>).format("DD-MMM-YYYY")
or
moment(<your Date goes here>).format("DD/MMM/YYYY")
... etc I hope you get the idea
Inside the format function, you put the desired format. The example above will get rid of all unwanted elements from the date such as minutes and seconds
answered Oct 16 '17 at 9:42
Adrian GrzywaczewskiAdrian Grzywaczewski
3551314
3551314
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L
,LL
, etc.)
– AJ Richardson
Apr 2 '18 at 21:46
add a comment |
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (L
,LL
, etc.)
– AJ Richardson
Apr 2 '18 at 21:46
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (
L
, LL
, etc.)– AJ Richardson
Apr 2 '18 at 21:46
This is not a good idea if you ever want to display your content in different locales. If you want to display dates in the correct format for the user's locale, you need to use one of the preset date formats (
L
, LL
, etc.)– AJ Richardson
Apr 2 '18 at 21:46
add a comment |
For people like me want the long date format (LLLL
) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:
var localeData = moment.localeData( moment.locale() ),
llll = localeData.longDateFormat( 'llll' ),
lll = localeData.longDateFormat( 'lll' ),
ll = localeData.longDateFormat( 'll' ),
longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
var formattedDate = myMoment.format(longDateFormat);
add a comment |
For people like me want the long date format (LLLL
) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:
var localeData = moment.localeData( moment.locale() ),
llll = localeData.longDateFormat( 'llll' ),
lll = localeData.longDateFormat( 'lll' ),
ll = localeData.longDateFormat( 'll' ),
longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
var formattedDate = myMoment.format(longDateFormat);
add a comment |
For people like me want the long date format (LLLL
) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:
var localeData = moment.localeData( moment.locale() ),
llll = localeData.longDateFormat( 'llll' ),
lll = localeData.longDateFormat( 'lll' ),
ll = localeData.longDateFormat( 'll' ),
longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
var formattedDate = myMoment.format(longDateFormat);
For people like me want the long date format (LLLL
) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:
var localeData = moment.localeData( moment.locale() ),
llll = localeData.longDateFormat( 'llll' ),
lll = localeData.longDateFormat( 'lll' ),
ll = localeData.longDateFormat( 'll' ),
longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
var formattedDate = myMoment.format(longDateFormat);
answered Apr 2 '18 at 21:58
AJ RichardsonAJ Richardson
4,1372948
4,1372948
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15130735%2fhow-can-i-remove-time-from-date-with-moment-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use Split method to separate the strings
– AmGates
Feb 28 '13 at 8:28