Skip to content

I18n Internationalizing dates

Bruno Krebs edited this page Jan 14, 2016 · 1 revision

I18n - Internationalizing dates

In order to use this library to format a date for different languages, one has to configure it properly before using. Like this:

var dateFormat = require('dateformat');

dateFormat.i18n = {
	dayNames: [
		'Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb',
		'Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'
	],
	monthNames: [
		'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez',
		'janeiro', 'fevereiro', 'março', 'bbril', 'maio', 'junho',
		'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'
	]
};

Now, if you call:

dateFormat(new Date(), 'd, mmmm, yyyy');

The output will be:

14, janeiro, 2016 // well actually it will be your current date, this is mine :D
Clone this wiki locally