How can I remove time from date with Moment.js?
up vote
171
down vote
favorite
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 |
up vote
171
down vote
favorite
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 |
up vote
171
down vote
favorite
up vote
171
down vote
favorite
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,8161563101
6,8161563101
asked Feb 28 '13 at 8:25
Obsivus
3,32593990
3,32593990
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
up vote
438
down vote
accepted
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/
62
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
18
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
up vote
28
down vote
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 |
up vote
11
down vote
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 |
up vote
6
down vote
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
up vote
3
down vote
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 |
up vote
2
down vote
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
up vote
2
down vote
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 at 12:45
add a comment |
up vote
1
down vote
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 at 21:46
add a comment |
up vote
0
down vote
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 |
up vote
0
down vote
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 |
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
438
down vote
accepted
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/
62
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
18
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
up vote
438
down vote
accepted
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/
62
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
18
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
up vote
438
down vote
accepted
up vote
438
down vote
accepted
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 yesterday
trojek
646729
646729
answered Oct 31 '13 at 6:03
Graham Charles
5,35332035
5,35332035
62
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
18
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
62
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
18
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
62
62
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
18
18
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
up vote
28
down vote
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 |
up vote
28
down vote
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 |
up vote
28
down vote
up vote
28
down vote
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 at 16:53
answered Apr 30 '16 at 0:52
Joshua Pinter
23.5k8134160
23.5k8134160
add a comment |
add a comment |
up vote
11
down vote
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 |
up vote
11
down vote
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 |
up vote
11
down vote
up vote
11
down vote
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 Jain
6561614
6561614
add a comment |
add a comment |
up vote
6
down vote
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
up vote
6
down vote
formatCalendarDate = function (dateTime) {
return moment.utc(dateTime).format('LL')
}
add a comment |
up vote
6
down vote
up vote
6
down vote
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,8161563101
6,8161563101
answered Feb 28 '13 at 8:31
AmGates
1,6781326
1,6781326
add a comment |
add a comment |
up vote
3
down vote
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 |
up vote
3
down vote
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 |
up vote
3
down vote
up vote
3
down vote
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 at 17:59
FlavorScape
4,89365492
4,89365492
answered Sep 10 '15 at 16:52
Torben Rahbek Koch
550314
550314
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 |
up vote
2
down vote
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
up vote
2
down vote
You can also use this format:
moment().format('ddd, ll'); // Wed, Jan 4, 2017
add a comment |
up vote
2
down vote
up vote
2
down vote
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 Raut
416
416
add a comment |
add a comment |
up vote
2
down vote
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 at 12:45
add a comment |
up vote
2
down vote
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 at 12:45
add a comment |
up vote
2
down vote
up vote
2
down vote
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 at 22:34
answered Aug 23 at 12:29
EquaPro
1012
1012
Add some ore description here
– Billa
Aug 23 at 12:45
add a comment |
Add some ore description here
– Billa
Aug 23 at 12:45
Add some ore description here
– Billa
Aug 23 at 12:45
Add some ore description here
– Billa
Aug 23 at 12:45
add a comment |
up vote
1
down vote
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 at 21:46
add a comment |
up vote
1
down vote
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 at 21:46
add a comment |
up vote
1
down vote
up vote
1
down vote
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 Grzywaczewski
3481314
3481314
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 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 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 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 at 21:46
add a comment |
up vote
0
down vote
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 |
up vote
0
down vote
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 |
up vote
0
down vote
up vote
0
down vote
Try this:
moment.format().split("T")[0]
Try this:
moment.format().split("T")[0]
edited Aug 28 '17 at 23:19
Moe A
3,74571227
3,74571227
answered Aug 28 '17 at 22:59
Keith Blanchard
1
1
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 |
up vote
0
down vote
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 |
up vote
0
down vote
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 |
up vote
0
down vote
up vote
0
down vote
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 at 21:58
AJ Richardson
4,0172948
4,0172948
add a comment |
add a comment |
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