>>DateTime TargetDate = DateTime.Now; >>>>How do I convert it to a string of the format "2019-02-28T19:00:00+03:00"?
>void Main() >{ > List<Product> myProducts = new List<Product> { > new Product { SKU="108.100.123", ListPrice=22, Price=16, CurrencyType="TRL", EffectiveFrom = DateTime.Now}, > }; > XNamespace ns = "urn:my-scripts"; > XDocument doc = new XDocument( > new XDeclaration("1.0","utf-8",""), > new XElement("Products", > new XAttribute(XNamespace.Xmlns+"user",ns), > from p in myProducts > select new XElement("Product", > new XElement("SKU", p.SKU), > new XElement("ListPrice", p.ListPrice), > new XElement("Price", p.Price), > new XElement("CurrencyType", p.CurrencyType), > new XElement("EffectiveFrom", p.EffectiveFrom) > ) > ) > ); > > var xml = new StringBuilder(); > using (XmlWriter xw = XmlWriter.Create (xml, new XmlWriterSettings { Indent = true })) > { > doc.Save (xw); > } > string sonuc = xml.ToString(); > Console.WriteLine (sonuc); >} > >public class Product >{ > public string SKU { get; set; } > public decimal ListPrice { get; set; } > public decimal Price { get; set; } > public string CurrencyType { get; set; } > public DateTime? EffectiveFrom { get; set; } >} >>
><?xml version="1.0" encoding="utf-16"?>
><Products xmlns:user="urn:my-scripts">
> <Product>
> <SKU>108.100.123</SKU>
> <ListPrice>22</ListPrice>
> <Price>16</Price>
> <CurrencyType>TRL</CurrencyType>
> <EffectiveFrom>2019-02-07T22:13:42.27652+03:00</EffectiveFrom>
> </Product>
></Products>
>
My code does not use the XML serializer. And I cannot change the code - now - just for this case. So, I will have to find a solution still.