Re: How to comvert "20030205195847Z" to DateTime
From: Jerry Pisk (jerryiii_at_hotmail.com)
Date: 06/24/04
- Next message: markeboy: "Serialize object with byte array"
- Previous message: scorpion53061: "Re: System.Data.SqlClient.SqlException: General network error. Check your network documentation."
- In reply to: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Next in thread: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Reply: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Reply: Marc Scheuner [MVP ADSI]: "Re: How to comvert "20030205195847Z" to DateTime"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Jun 2004 18:52:36 -0700
Just a little note - that Z at the end of the time string is probably a time
zone, not a literal Z character.
Jerry
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b43f690c740df398ad7a@msnews.microsoft.com...
> Peter van der Goes <p_vandergoes@toadstool.u> wrote:
>> > I have a timestamp value equals to "20030205195847Z" that I
>> > retrieved
>> > from a LDAP property. I got an exception "String was not recognized as
>> > a
>> > valid DateTime" when I used Convert.ToDateTime(). Do you know how to
>> convert
>> > it to a DateTime.
>
>> First, I suggest you use the DateTime class Parse() method to parse the
>> string. You'll need to convert your string to a format acceptable to
>> Parse(), like:
>>
>> String s = "02/05/2003 19:58:47Z";
>>
>> which works fine.
>
> There's no need to change the string's format to start with. Try this:
>
> using System;
> using System.Globalization;
>
> class Test
> {
> static void Main()
> {
> string date = "20030205195847Z";
> string format = "yyyyMMddHHmmss'Z'";
> DateTime dt = DateTime.ParseExact
> (date, format, CultureInfo.InvariantCulture);
> Console.WriteLine(dt);
> }
> }
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: markeboy: "Serialize object with byte array"
- Previous message: scorpion53061: "Re: System.Data.SqlClient.SqlException: General network error. Check your network documentation."
- In reply to: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Next in thread: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Reply: Jon Skeet [C# MVP]: "Re: How to comvert "20030205195847Z" to DateTime"
- Reply: Marc Scheuner [MVP ADSI]: "Re: How to comvert "20030205195847Z" to DateTime"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|