-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdateFormatter.js
32 lines (29 loc) · 1004 Bytes
/
dateFormatter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let datum = new Date()
let formatum = "%Y-%M-%d"
let langum = 'en-us'
const dateFormatter = (date, formatting, lang) => {
let numbers = {
"%Y": datum.getYear() + 1900,
"%M": datum.getMonth() + 1,
// This returns a string representation of the month
// But the language code in lang will only work
// iff you have the language installed somehow
// Therefore this wont work on all devices and such
"%m": date.toLocaleString(lang, { month: 'long' }),
"%d": datum.getDay(),
}
return formatting.split("-").map(x => numbers[x]).join(" ")
//let utputt = ""
/*
for (let thing of formatting.split("-")) {
utputt += numbers[thing] + " "
}
return utputt;
*/
}
console.log(dateFormatter(datum, "%m-%Y-%d", langum))
console.log(dateFormatter(datum, "%m-%Y-%d", "ko-KR"))
console.log(dateFormatter(datum, "%m-%Y-%d", "de-de"))
console.log(dateFormatter(datum, "%m-%Y-%d", "de"))
console.log(dateFormatter(datum, "%m-%Y-%d", "no-bok"))
console.log(dateFormatter(datum, "%m-%Y-%d", "no"))