Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
How to parse JSON format date string into date format

What I am doing is, fetching data from database using ajax and show it on html text boxes for update purposes. Below is my Web Method code from where I get data successfully.

[WebMethod]
public static List<Employee> getEmployee()
{
     var slist = new List<Employee>();
     var db = new BLUEPUMPKINEntities();
     slist = db.Employees.ToList();
     return slist;
}

Now when I get data from database I got date in this format /Date(725828400000)/. I search google about parse and converting json date string format into html / javascript date also use 3rd party plugins like moment.js and jquery.ui but not solve my problem. Also here I am sharing my code from which I get data from ajax in json format and show it on jquery datatable.

$.ajax({
    url: "Employees.aspx/getEmployee",
    data: null,
    contentType: "Application/json; charset=utf-8",
    responseType: "json",
    method: "POST",
    success: function (response) {
        //alert(response.d);

        var jsonObject = response.d;
        var result = jsonObject.map(function (item) {
            //var date = new Date(item.EMP_DOB);
            //var obj = Date.parse(date);
            var result = [];
            result.push('');
            result.push(item.EMP_FNAME);
            result.push(item.EMP_MNAME);
            result.push(item.EMP_LNAME);
            result.push(item.EMP_EMAIL);
            result.push(item.EMP_DOB); //this is my date column in my database from where date is in yyyy/mm/dd format
            result.push(item.EMP_USERNAME);
            result.push(item.EMP_PASSWORD);
            result.push(item.ID);
            return result;
        });
        myTable.rows.add(result); // add to DataTable instance
        myTable.draw();
    },
    error: function (xhr) {
        alert(xhr.status);
    },
    Failure: function (response) {
        alert(response);
    }
});

I want date in mm/dd/yyyy format. Please help me to solve my prob.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

If there is no issue in adding a dependency, then you can add moment.js and it will help you to format data in any format I am supposing that date from server is in this format '/Date(725828400000)/'

var d = item.EMP_DOB;
result.push(moment(Number(d.match(/\d+/)[0])).format('MM/DD/YYYY'));

If you are unable to add moment js then you can do soemthing like

var date = new Date(Number(d.match(/\d+/)[0]));
var day = date.getDate();
day = day = (day < 10) ? ("0" + day) : day;
var month = date.getMonth() + 1);
month = (month < 10) ? ("0" + month) : month;
var dateStr = day + "-" + month + "-" + date.getFullYear();
result.push(dateStr);
over 4 years ago · Santiago Trujillo Relatório

0

Easiest way to do is below (no third party js required)

var data =from row in db.Employees.ToList()
 select new {
    EMP_DOB=row.EMP_DOB.ToString(), row.EMP_FNAME,row.EMP_MNAME,row.EMP_LNAME
     row.EMP_EMAIL,row.EMP_DOB,row.EMP_USERNAME,row.EMP_PASSWORD,row.ID
 };

If you want to format the date you can use

var data =from row in db.Employees.ToList()
     select new {
         EMP_DOB=Convert.ToString(row.EMP_DOB).ToShortDateString(), other properties goes here as shown previously
     };

You wil be able to format it whatever you want using C#

over 4 years ago · Santiago Trujillo Relatório

0

You already have a data object, which has its methods to extract everything you need.

You can make a function like in this example:

Get string in yyyymmdd format from js date object

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda