[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

about dates with timezone

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?
0
FLUXWIRE
Asked:
FLUXWIRE
  • 4
  • 2
  • 2
1 Solution
 
Timbo87Commented:
Try this:

DateTime dt = DateTime.Parse("20050218T110000Z");
0
 
FLUXWIREAuthor Commented:
I already had tried it before post this!

" String was not recognized as a valid DateTime"
this is the result.
0
 
Timbo87Commented:
Is that date supposed to be Feb. 2, 2005?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
FLUXWIREAuthor Commented:
no!
the date is Feb. 18, 2005 at 11:00
0
 
God_AresCommented:
looks like iso 8601  http://www.cl.cam.ac.uk/~mgk25/iso-time.html

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,":");
0
 
FLUXWIREAuthor Commented:
yes. this is a solution. an alternate solution.

this value is comming from the exchange appointment recurrence rules.

there is not another way?
0
 
God_AresCommented:
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

<quote>
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.]
</quote>

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,..

regards

Floris Briolas




0
 
FLUXWIREAuthor Commented:
thx. i agree!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now