about dates with timezone

Posted on 2004-10-27
Last Modified: 2010-05-18
Hi all!
I got dates in this format "20050218T110000Z" from Microsoft exchange properties.
This dates comes as strings and i need to parse it to select a date in a datepicker control.
but this format is not convertible.

Any ideas?
Question by:FLUXWIRE
    LVL 15

    Expert Comment

    Try this:

    DateTime dt = DateTime.Parse("20050218T110000Z");

    Author Comment

    I already had tried it before post this!

    " String was not recognized as a valid DateTime"
    this is the result.
    LVL 15

    Expert Comment

    Is that date supposed to be Feb. 2, 2005?

    Author Comment

    the date is Feb. 18, 2005 at 11:00
    LVL 7

    Expert Comment

    looks like iso 8601

    just remove z,.. put some slashes in and some : and you are all set to parse it,..

                      string StringFromExchange = "20050218T110000Z";
                      string ToParse = StringFromExchange.Substring(0,StringFromExchange.Length-1).Insert(4,"-").Insert(7,"-").Insert(13,":").Insert(16,":");

    Author Comment

    yes. this is a solution. an alternate solution.

    this value is comming from the exchange appointment recurrence rules.

    there is not another way?
    LVL 7

    Accepted Solution

    if you can validate the returned dateformate is as described in  iso 8601,..  

    you might reconise the format

    //non compiled code here
    MessageBox.Show(DateTime.Now.Tostring("s")); //should show something like 2004-10-18T14:48:33  

    also these do

    System.Globalization.DateTimeStyles.Exchange; //does not exsist ;)

    hmm reading some text in the link i gave you,.. if a 'Z' is placed at the end it means the timezone is UTC

    Time Zone
    Without any further additions, a date and time as written above is assumed to be in some local time zone. In order to indicate that a time is measured in Universal Time (UTC), you can append a capital letter Z to a time as in

    23:59:59Z or 2359Z

    [The Z stands for the "zero meridian", which goes through Greenwich in London, and it is also commonly used in radio communication where it is pronounced "Zulu" (the word for Z in the international radio alphabet). Universal Time (sometimes also called "Zulu Time") was called Greenwich Mean Time (GMT) before 1972, however this term should no longer be used. Since the introduction of an international atomic time scale, almost all existing civil time zones are now related to UTC, which is slightly different from the old and now unused GMT.]

    so you should  DateTiem.Parse(str).ToLocalTime(); //SOOOO important

    in reply to your last statement,... what other way?,.. an other way to convert this string?  I'ts quite obvious it's an iso 8601 string,.. so my solution is OK!

    if it aint the right solution for you,.. so be it,..


    Floris Briolas


    Author Comment

    thx. i agree!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now