I need to format the current datetime to inject into an xml document in 'xsd:dateTime' format. How do I do that here?
Dim FileName As String = HttpContext.Current.Server.MapPath("~/specs/xml/sample.xml")
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(FileName)
'getting element
Dim lNode As XmlElement = xmlDoc.GetElementsByTagName("LNode")(0)
'setting the current date attribule on LNode
lNode.SetAttribute("CurrentDateTime", Now.ToString("YYYY-MM-DDTHH:MM:SS"))
'lNode.SetAttribute("CurrentDateTime", XmlConvert.ToDateTime(Now.ToString, 0)) 'doesnt work either
Member
301 Points
393 Posts
Formatting DateTime correctly for XML
Oct 28, 2010 06:01 PM|kevorkian|LINK
I need to format the current datetime to inject into an xml document in 'xsd:dateTime' format. How do I do that here?
Any idea how I format this correctly?
All-Star
124318 Points
10142 Posts
Moderator
Re: Formatting DateTime correctly for XML
Oct 28, 2010 06:13 PM|SGWellens|LINK
// "s" means SortableDateTimePattern,
// which is based on ISO 8601 and
// what XML schema uses for DateTime format
...DateTime.Now.ToString("s")
My blog
Member
301 Points
393 Posts
Re: Formatting DateTime correctly for XML
Oct 28, 2010 06:27 PM|kevorkian|LINK
Excellent! That was quick and painless, thanks a million!