I have set the short date format to "dd/MM/yyyy" in the currentCulture and currentUICulture. However when I try to serialize the object having date time attribute, it still serialize object into xml in "MM/dd/yyyy" format (which is the default format in my machine). Code:
public static string SerializeObject(this object data)
{
var serializer = new DataContractSerializer(data.GetType());
var output = new StringWriter();
using (var writer = new XmlTextWriter(output) { Formatting = Formatting.Indented })
{
serializer.WriteObject(writer, data);
}
return output.GetStringBuilder().ToString();
}
My object structure looks like this
[Serializable]
Class MyClass
{
DateTime? ProcessDate {get; set;}
}
Instance of MyClass has the ProcessDate value formatted in the short date format specified in the current thread. when I deserialize it takes the short date format mentioned in Current thread's culture.
how to serialize with specific datetime format mentioned in the current thread culture and not by date time format specified at machine level.