Reputation:
I want to display the date clicked on in a specific format with localised strings, but although it shows the locale being set, the string I get is this:
Fri Jun 05 2015 00:00:00 GMT+0300 (EEST)
I would like to turn that into Friday, 5. June 2015
with localised words.
On the clickEvents when I console.log
the target
I get the wrong string under date._d
although under date._locale
in date I see the localised stuff as well.
And I really don't understand how to change the format once I use target.date.toDate()
.
My clickEvents in the CLNDR initiation:
clickEvents: {
click: function (target) {
$('.selected-date').text(target.date.toDate());
console.log(target);
}
},
Not sure if this is a Moment or CLNDR issue, but I am leaning towards Moment, since CLNDR is using it.
And this is what gets returned by the console.log
:
{
element: div.day.today.calendar-day-2015-06-05.calendar-dow-4,
events: Array[0], date: Moment,
date: Moment {
_d: Fri Jun 05 2015 00:00:00 GMT+0300 (EEST)
_f: "YYYY-MM-DD "
_i: "2015-06-05"
_isAMomentObject: true
_isUTC: false
_locale: Locale
_pf: Object
__proto__: Moment
element: div.day.today.calendar-day-2015-06-05.calendar-dow-4
events: Array[0]
__proto__: Object
}
}
Something like that. Any help appreciated.
Upvotes: 3
Views: 1271
Reputation: 2814
You can't really "roll your own" when it comes to localized dates because every locale has its own set of localized date strings. This is because different countries display their dates differently.
Why don't you want to use a country's format? If someone from another country uses your site, they will find a different date format odd.
You can get similar to what you're looking for with:
moment(date).format('dddd, LL');
For US, that would print
Thursday, September 4 1986
Upvotes: 1