Formato de fechas al exportar un dataset a XML

Cuando se exporta un dataset a XML, las fechas se formatean según la timezone del equipo donde se está ejecutando la exportación.

Ej, si la fecha es
     2003-04-06T00:00:00

cuando se exporta a XML puede quedar así
     2003-04-06T00:00:00-03:00

En este caso le agregó el GMT -3

Una solución posible es cambiar el DateTimeMode del dataset a Unspecified.
De esta forma, no se incluirá el offset (el -3) en el archivo XML.


System.Data.DataSet data = new DataSet();

// ...

// Iterate the columns and set DataColumn.DateTimeMode
// to DataSetDateTime.Unspecified to remove offset
// when serialized.
foreach (DataTable table in data.Tables)
{
    foreach (DataColumn item in table.Columns)
    {
        // Switching from UnspecifiedLocal to Unspecified
        // is allowed even after the DataSet has rows.
        if (item.DataType == typeof(DateTime) &&
            item.DateTimeMode == DataSetDateTime.UnspecifiedLocal)
        {
            item.DateTimeMode = DataSetDateTime.Unspecified;
        }
    }

}

Fuente: http://blog.scosby.com/post/2013/03/01/Serializing-A-DataSet-With-DateTime-Columns.aspx

No hay comentarios:

Publicar un comentario