I need to compare dates but the finnish date format does not seem to be supported (thanks javascript!).
Here is the code that should return the difference between 2 dates (one of them being today):
function jämförMedIdag (datum) {
if (datum == null || datum == "") {
alert('Inget datum!');
return;
}
var datum = new Date(datum);
var dagar = datum.getDate();
var månader = datum.getMonth();
var år = datum.getYear();
var nyttDatum = new Date();
nyttDatum.setFullYear(år,månader,dagar);
var idag = new Date();
if(nyttDatum>idag) {
var svar = nyttDatum - idag;
return(svar);
} else {
var svar = idag - nyttDatum;
return(svar);
}
}
How can I tell javascript that my date is in format dd.mm.yyyy or dmyyyy or dd.m.yyyy or d.mm.yyyy?
JavaScript中没有像strptime
这样的函数,因此您必须使用split
或match
这样的字符串操作函数strptime
解析它。
Just parse it yourself:
var parts = datum.split('.');
datum = new Date();
datum.setFullYear(parts[2],parts[1]-1,parts[0]);
Etc.
If you don't want to write a parser from scratch you can give a try to Date.js , an open source library which has 150+ localized plugins. There's a Finnish version too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.