0

in my client side i get an object with a datetime property so when i send the object to the server side i send it in json format so when i try to use that property appears in a different format.

the original datetime property is "2016-03-09T17:16:33" and when i try to use that property appears like this: "09/03/2016 05:16:33 p. m."

what i want is to avoid that cast, or reformat the property to the original format.

im using Newtonsoft.Json to handle the json in the server side.

this is the client side´s object (angularjs)

var factura = {
      comprobante:{
       
        fecha:"2016-03-09T17:16:33",
         version:"3.2",
        tipoDeComprobante:"comprobante",
        formaDePago:"Efectivo",
        subTotal:"123123.123",
        total:"4234234",
        metodoDePago:"deposito",
        LugarExpedicion:"guadalajara"
      },
      cliente:{
        token:"69113116100"
      },
      receptor:{
        rfc:"234dfdg3gfdgsg42",
        domicilio:{
        pais:"Mexico"
        }
      },
      emisor:{
        rfc:"234dfdg3gfdgsg42",
        domicilioFiscal:{
          calle:"san cristobalito",
          municipio:"zapopan",
          estado:"jalisco",
          codigoPostal:"3434",
          pais:"mexico"
        },
        regimenFiscal:{
          Regimen:"regimen"

        }
      },
      conceptos:
      [
        {
          cantidad:"234",
          unidad:"1.0",
          descripcion:"descripcion",
          valorUnitario:"decimal",
          importe:"importe"
        },
         {
          cantidad:"234",
          unidad:"1.0",
          descripcion:"descripcion",
          valorUnitario:"decimal",
          importe:"importe"
        }
      ],
      impuestos:{
        traslado:[
          {
           impuesto:"1.3",
           tasa:"2.5",
          importe:"importe"
        },
         {
          
          impuesto:"1.3",
           tasa:"2.5",
          importe:"importe"
        }

        ],
         retencion:[
          {
           
          impuesto:"1.3",
           tasa:"2.5",
          importe:"importe"
        },
         {
         
          impuesto:"1.3",
           tasa:"2.5",
          importe:"importe"
        }

        ]

      },
      tieneComplementoDonat:"0"


        };

and this is my server side´s code as you can see in the comprobante.SetAttributeValue(DatosComprobante[y].NombreDato, objeto["factura"]["comprobante"][DatosComprobante[y].NombreDato]); method i insert the properties in a XElement node so when the property "fecha" comes in the for loop, it appears different as i sent it from client's side. i think is something about to disable the deserialization to get only the raw string because when i see the "objeto" variable in the debugger the date appears correctly.

 public XElement retornaNodoXml(JObject objeto)
    {
        Domicilio domicilio = new Domicilio();
        Dato dato = new Dato();
        XElement comprobante = new XElement("cfdi" + dato.ComodinCfdi + "Comprobante");

        for (int y = 0; y < DatosComprobante.Count; y++)
        {
            if (objeto["factura"]["comprobante"][DatosComprobante[y].NombreDato] != null)
            {

                comprobante.SetAttributeValue(DatosComprobante[y].NombreDato, objeto["factura"]["comprobante"][DatosComprobante[y].NombreDato]);

            }
        }



        return comprobante;
    }
checo
  • 49
  • 1
  • 8
  • Can you show some of your code? – Matt Rowland Apr 25 '16 at 21:53
  • view this topic : http://stackoverflow.com/questions/7670629/how-to-force-netwtonsoft-json-serializer-to-serialize-datetime-property-to-strin – Abdellah OUMGHAR Apr 25 '16 at 21:55
  • i've updated the question – checo Apr 25 '16 at 23:20
  • Your JSON is fine, except you should set `DateTimeKind.Utc` on the `DateTime` object such that it gets serialized with a trailing `Z`. This is the ISO8601 / RFC3339 standard format. Your question about formating for display has noting to do with your C# code though. For that, you need to reformulate your question to show the JavaScript side of things. – Matt Johnson-Pint Apr 25 '16 at 23:27

0 Answers0