I'm trying to generate timestamp for cXML as shown below. Is there any function in C# which I can use to format date time to: 2011-06-09T16:37:17+16:37
e.g.
<cXML payloadID="[email protected]" timestamp="2011-06-09T16:37:17+16:37">
The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where: YYYY indicates the year. MM indicates the month. DD indicates the day.
Can use the following conversion code to convert UTC format string to any other DateTime format. string result = Convert. ToDateTime("2011-02-04T00:00:00+05:30"). ToString("MM/dd/yyyy h:mm:ss tt");
The standard XSD DateTime and Date formats are CCYY-MM-DDThh:mm:ss and CCYY-MM-DD, respectively, because the underlying XSD schema of the DataSet maps the DateTime and Date columns of the database to the DateTime and XSD Date data types.
What is XML? The Extensible Markup Language (XML) is a simple text-based format for representing structured information: documents, data, configuration, books, transactions, invoices, and much more. It was derived from an older standard format called SGML (ISO 8879), in order to be more suitable for Web use.
Use the "o" format specifier - read about this one in the standard Date and Time format strings documentation on MSDN.
The pattern for this specifier reflects a defined standard (ISO 8601).
And:
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000
string formatted = DateTime.Now.ToString("o");
If this is not what you want, you will need to use a custom format string - I believe you will need to do this, as the offset is not standard.
string formatted = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssK");
Yes, using DateTime.ToString("s")
, see this link: Standard Date and Time Format Strings. Be aware that "s"
does not include the timezone information, whereas "o"
does include both fractional seconds and timezone.
You can also use the XmlConvert.ToString
method, where you can specify the time zone information as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With