This is my code
$scope.getWeekDayShort = function(date) {
moment().locale('pt-br');
return moment(date, "D_M_YYYY").format('ddd');
}
it returns name of weekday in english but need portuguese weekday name
If I pass 1_1_2015 it returns Thu
How can I get weekday name in portuguese?
EDIT
moment.locale('pt-br');
console.log(JSON.stringify(moment.months())) // ["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"]
moment.locale('en');
console.log(JSON.stringify(moment.months())); // ["January","February","March","April","May","June","July","August","September","October","November","December"]
I have included moment-with-locales.min.js file which includes all supported language data and it work good with upper code. So why it not works with week name ?
Try this (source):
moment(date, "D_M_YYYY").locale('pt-br').format('ddd')
Might be worth it to log an issue on the GitHub page, I think your code should work or the docs should be improved.
Related
I'm trying to set up the current time of a process but I just want to set up the day not the time/seconds like Tue, 28 Sep 2021.
I know 2 ways of doing dates and that would be:
new Date().toTimezoneString() and firebase.firestore.FieldValue.serverTimestamp() both of them includes time though.
and I know that if I set up Date() alone it store the data as a date format instead of a string.
Extra: can it be set up in other languages as well ?
Use Intl ( Internationalization API ) to format your dates. It's supported by all browsers and provides a comprehensive api to suit your date and time formatting needs.
Here is the doc for the method you need:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
For your use-case where you dont want to show time, you simply do not pass timeStype in the options parameter to the Intl formatter. Example would be
const date = new Date();
const formattedDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }).format(date)
Can someone tell me, how I can define another calendar's locale (e.g. German) for the rendered calendar parts of the nice gantt feature in plantUML
I have something like:
#startgantt
-- Vorbereitung --
Project starts 2020-12-01
[Themenfindung] starts 2020-12-01 and ends 2021-01-01
[milestone] happens at 2020-12-15
-- ... --
#endgantt
The output prints month and daynames in English:
Is it possible at all and if so how can this be changed to German.
There is nothing about this in the documentation (https://plantuml.com/de/gantt-diagram).
With last beta http://beta.plantuml.net/plantuml.jar you can now specify a language for the Calendar.
For example:
#startgantt
Language DE
Project starts the 20th of september 2017
...
#endgantt
This will be integrated in next official release.
According to their source code,
there are hardcoded values for days and months as Enums
and they use name() method to get their English names.
I would recommend you to clone their repo and change the hardcoded values in two classes:
In file src/net/sourceforge/plantuml/project/time/DayOfWeek.java
replace method shortName like this:
public String shortName() {
Locale locale = Locale.getDefault();
String s = StringUtils.capitalize(java.time.DayOfWeek.valueOf(this.toString()).getDisplayName(TextStyle.SHORT_STANDALONE, locale));
return s.substring(0,2);
}
In file src/net/sourceforge/plantuml/project/time/Month.java
replace two methods like this
public String shortName() {
return StringUtils.capitalize(java.time.Month.valueOf(this.toString()).getDisplayName(TextStyle.SHORT_STANDALONE,Locale.getDefault()));
}
and
public String longName() {
return StringUtils.capitalize(java.time.Month.valueOf(this.toString()).getDisplayName(TextStyle.FULL_STANDALONE,Locale.getDefault()));
}
I compile only these two classes and replace them in jar file. This works for me.
Mike.
I am using moment.js and getting this error:
Deprecation warning: value provided is not in a recognized RFC2822 or
ISO format. moment construction falls back to js Date(), which is not
reliable across all browsers and versions. Non RFC2822/ISO date
formats are discouraged and will be removed in an upcoming major
release. Please refer to
http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: [0] _isAMomentObject: true, _isUTC: false, _useU
In my react component I have:
const sortTasks = (first, second) => moment(first.endDate).diff(second.endDate);
The first.enddate=‘20 dec 2018’
How can I avoid this warning in the console?
One alternative is to inform moment.js about the date format used, by providing a second parameter to the moment function.
The format of "20 dec 2018" is DD MMM YYYY".
If you have both dates in the same format, you should write
const sortTasks = (first, second) =>
moment(first.endDate, "DD MMM YYYY").diff(moment(second.endDate, "DD MMM YYYY"));
Note that the other date is also explicitly transformed to a moment, since it is expressed in a non-standard format.
You can check the details in the moment.js documentation about parsing.
If you want to find out the difference expressed in days, or in e.g. years / months / days, you can use moment.duration. Check the moment.js documentation about this feature.
E.g. to obtain the number of years, months and days between two dates, say date1 and date2, we could proceed as follows (assuming date1 is before date2):
const theDuration = moment.duration(date2, date1);
const yearsElapsed = theDuration.years();
const monthsElapsed = theDuration.months();
const daysElapsed = theDuration.days();
Hope it helps - Carlos
I am trying to implement a date-sorting method for a news list that works across browsers. However, the one method I have tried that works well, only works in Chrome:
origArt.sort(function(a, b) {
var dateA = new Date(a.date), dateB = new Date(b.date);
return dateB - dateA;
});
I also tried this code, suggested in other sorting questions as a possible solution:
origArt.sort(function(a,b){
return (b.date > a.date) ? 1 : (b.date < a.date) ? -1 : 0;
});
But, because the dates in my JSON vary from year; month & year; and month, year and day; the news list sorts in reverse
alphabetical order, not reverse chronological order.
They are strings such as: "2018.", "April 8, 2015.", and "September 2015."
Your problem is that those aren't valid date strings. From some quick testing, Chrome appears to be doing a bit of guesswork as to what you mean, but the other browsers aren't.
Chrome:
new Date("2018.")
// Mon Jan 01 2018 00:00:00 GMT-0800 (Pacific Standard Time)
Firefox:
new Date("2018.")
// Invalid Date
And since Invalid Date > Invalid Date is always false, it isn't sorting anything. It's not just a matter of removing the period either, since "September 2015" also works in Chrome but fails in Firefox.
Ideally, you should fix your JSON or whatever code it's being generated from to use parseable date strings. If that's not an option, you'll probably have to write a custom parsing function that handles all the possible formats you might get, or see if a library like Moment.js can handle it for you.
I have a date formatted as a ISO-8601 string: overview.startTime = "2017-05-09T08:00:00Z"
I want to display this on my page and I have used the following code:
Dagens arbetspass {{overview.startTime | date:'dd-MMM'}}
This is displayed as "Dagens arbetspass 09-May". My problem is that this is a Swedish site, and in Sweden we don't start the month names with an uppercase character. Also May is written "maj" (j in the end and not y). I tried to add the timezone like this
Dagens arbetspass {{overview.startTime | date:'dd-MMM':'Europe/Stockholm'}}
but that did not change the output. In fact, most months are spelled differently in Swedish. Any suggestions?
Just use the javascript "toLocaleDateString" method to resolve the concern. The method takes two arguments which are 'locale' and 'options'.
Locale will be "sv-se" for swedish.
Options will provide the format to your string. For example -var options = { weekday: "long", year: "numeric", month:long",day:"numeric" };
var d = new Date("2017-05-09T08:00:00Z");
date.toLocaleDateString("sv-se", options)
Here's a plunker https://plnkr.co/edit/G2IL5Zv0OAcVRMZS9HB7