Skip to content

Instantly share code, notes, and snippets.

@Kamilnaja
Created November 13, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kamilnaja/8df5b5afe49c45e37cbd2cf75c1b7981 to your computer and use it in GitHub Desktop.
Save Kamilnaja/8df5b5afe49c45e37cbd2cf75c1b7981 to your computer and use it in GitHub Desktop.
// 1
const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
console.log(new Intl.DateTimeFormat('pl-PL', {dateStyle: 'full'}).format(date));
// niedziela, 20 grudnia 2020
// 2
const vehicles = ['Motor', 'bus', 'samochód'];
const formatter = new Intl.ListFormat('pl', { style: 'long', type: 'conjunction' });
console.log(formatter.format(vehicles));
// Motor, bus i samochód
const formatter2 = new Intl.ListFormat('pl', { style: 'short', type: 'disjunction' });
console.log(formatter2.format(vehicles));
// Motor, bus lub samochód
// 3
const number = 123456.789;
console.log(new Intl.NumberFormat('pl-PL', { style: 'currency', currency: 'PLN' }).format(number));
// expected output: "123.456,79 zł
// 4
// Create a relative time formatter in your locale
// with default values explicitly passed in.
const rtf = new Intl.RelativeTimeFormat("pl", {
localeMatcher: "best fit", // other values: "lookup"
numeric: "always", // other values: "auto"
style: "long", // other values: "short" or "narrow"
});
// Format relative time using negative value (-1).
console.log(rtf.format(-1, "day"));
// 1 dzień temu
// Format relative time using positive value (1).
console.log(rtf.format(1, "day"));
// za jeden dzień
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment