I wish to create a string from the current date now() so that it looks
like
the format used by Excel, for instance:
2006-04-16T19:45:42Z
That is ISO 8601 Format. It indicates a UTC (Coordinated Unitversal Time)
time, which is the DateTime at 0 degrees longitude (Greenwhich Mean Time -
TMT). So, in order to format your DateTime value properly, you must first
convert it to UTC time, using the DateTime.ToUniversalTime() method, and
then call the DateTime.ToString(string format) overload, passing in the
following Custom DateTime string:
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
Unfortunately, the CLR includes Standard DateTime strings that come close,
but not exactly. The closest is "U" which translates to UTC time format
without the "T" before the hh:mm:ss portion.
Example:
DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'")
Note that the time is translated to GMT time by default with the assumption
that it is local time. Otherwise, you need to convert the Time to local
first. You can read more about this subject here:
http://msdn2.microsoft.com/en-us/library/system.datetime.aspx
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net