471,079 Members | 961 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,079 software developers and data experts.

How to format a date to look like 2006-04-16T19:45:42Z


Hi,

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

How would I achieve that?

Thank you,

-Pam

PS
Btw does that format has a name?

Apr 25 '07 #1
3 1499
Hello,
2006-04-16T19:45:42Z
It's the ISO8601-based format.

System.DateTime.Now.ToString("s"); is a good start.

(H) Serge
Apr 25 '07 #2
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/lib....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

"pamela fluente" <pa***********@libero.itwrote in message
news:11*********************@b40g2000prd.googlegro ups.com...
>
Hi,

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

How would I achieve that?

Thank you,

-Pam

PS
Btw does that format has a name?

Apr 25 '07 #3
On 25 Apr, 19:32, "Kevin Spencer" <unclechut...@nothinks.comwrote:
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.
Thank you very much Kevin and Serge,

I will try that.

Very helpful

Cheers,

-Pam

Apr 26 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by praba kar | last post: by
4 posts views Thread by peashoe | last post: by
reply views Thread by lsy | last post: by
1 post views Thread by Keith Chadwick | last post: by
2 posts views Thread by fniles | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.