-2
The date is filled in according to the information obtained from a JSON response
Script
$(document).ready(function () {
$("#@(Model.Campo)_Nome").typeahead({
source: function (query, process) {
return $.get('@Url.Action("PesquisarAlgumaCoisa", "AlgumaCoisa")', { nome: query, somenteAtivas: '@Model.SomenteAtivas' }, function (data) {
return process(data);
}, "json");
},
autoSelect: true
}).change(function (event) {
var current = $(event.target).typeahead("getActive");
$("#@Model.Campo").val("");
$(".dataFim").html("");
if (current && current.name == $(event.target).val()) {
$("#@Model.Campo").val(current.id);
$(".dataFim").html(dataFormatada(current.DataFim));
}
});
function dataFormatada(data){
dia = data.getDate().toString(),
diaF = (dia.length == 1) ? '0'+dia : dia,
mes = (data.getMonth()+1).toString(), //+1 pois no getMonth Janeiro começa com zero.
mesF = (mes.length == 1) ? '0'+mes : mes,
anoF = data.getFullYear();
return diaF+"/"+mesF+"/"+anoF;
I’ve tried in some ways, like:
$(".dataFim").html(current.DataFim.toString("dd/MM/yyyy"));
$(".dataFim").html(current.DataFim.toLocaleTimeString());
Does this Answer your Question? How to format date in javascript?
– Icaro Martins
@Icaromartins does not present another error
– Lucas Ost