var data = new Date();
console.log(data.toLocaleDateString());
console.log(data.toLocaleDateString("pt-BR"));
console.log(data.toLocaleDateString("pt-PT"));
console.log(data.toLocaleDateString("en-US"));
var data = new Date();
var options = {};
options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }
console.log(data.toLocaleDateString([], options));
options = { timeZone: 'UTC', timeZoneName: 'short' }
console.log(data.toLocaleDateString([], options));
E um exemplo a titulo de curiosidade, alterando o calendaio e o sistema numerico da data:
var sistemas = ["arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt"];
var calendarios = ["buddhist", "chinese", "coptic", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamicc", "iso8601", "japanese", "persian", "roc"]
var data = new Date();
var datas = sistemas.map(function (sistema) {
return {
sistema: sistema,
calendarios: calendarios.map(function (calendario) {
var format = "pt-BR-u-nu-" + sistema + "-ca-" + calendario;
try {
return {
calendario: calendario,
format: format,
exemplo: data.toLocaleDateString(format)
}
} catch (e) {
}
})
}
});
var srce = document.getElementById("tmpl");
var tmpl = Handlebars.compile(srce.innerHTML);
document.body.innerHTML = tmpl(datas);
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.1/handlebars.js"></script>
<script id="tmpl" type="text/template" >
<table>
<thead>
<tr>
<th></th>
{{#each this.[0].calendarios}}
<th>{{calendario}}</th>
{{/each}}
</tr>
</thead>
<tbody>
{{#each this}}
<tr>
<th>{{sistema}}</th>
{{#each calendarios}}
<td><a href="#" title="{{format}}">{{exemplo}}<a></td>
{{/each}}
</tr>
{{/each}}
</tbody>
<table>
</script>
para ver o formato utilizado, basta passar o mouse sobre a tabela.
Se você quizer que todos no globo vejam a data no formato dd/MM/yyyy
, use .toLocaleDateString('pt-BR-u-nu-latn-ca-gregory')
.