Skip to content

Instantly share code, notes, and snippets.

@viniciusdaniel
Created October 29, 2014 23:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save viniciusdaniel/c4775e9d53caa64ff467 to your computer and use it in GitHub Desktop.
Save viniciusdaniel/c4775e9d53caa64ff467 to your computer and use it in GitHub Desktop.
D3.js localize pt-BR for time and number formatting
/**
* Configuração de localização em Português do Brasil(PT-BR) para o D3.js realizar formatação tempo e números
* Mais detalhes conferir a documentação: https://github.com/mbostock/d3/wiki/Time-Formatting
*/
var localized = d3.locale({
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["R$", ""],
"dateTime": "%d/%m/%Y %H:%M:%S",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
"shortDays": ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
"months": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
"shortMonths": ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
});
var date = new Date(1986, 1, 13);
var formatter = localized.timeFormat("%A, %d %B %Y");
console.log(formatter(date)); // "Quinta, 13 Fevereiro 1986"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment