473,799 Members | 3,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unexpected result using DateTime.ParseE xact

Hi,

I've the following line of code:

result = DateTime.ParseE xact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ",
CultureInfo.Inv ariantCulture);

where I get in result "result" "02.12.1999 00:59:59" instead of teh
expected "01.12.1999 23:59:59"
Anybody a idea ?

Thanx Peter

Nov 4 '07 #1
11 9841
Peter Holschbach wrote:
I've the following line of code:

result = DateTime.ParseE xact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ",
CultureInfo.Inv ariantCulture);

where I get in result "result" "02.12.1999 00:59:59" instead of teh
expected "01.12.1999 23:59:59"
Anybody a idea ?
result = DateTime.ParseE xact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.Inv ariantCulture);

gives the correct result for me (I am in GMT-5).

Arne
Nov 4 '07 #2
Stephany Young wrote:
You specified 'Z' in the format string ("yyyy-MM-ddTHH:mm:ssZ")
therefore your value string MUST end with a 'Z' otherwise the call to
DateTime.ParseE xact will fail. ParseExact means just that (it must macth
EXACTLY).
The problem is that Z apperently do effect the parsing.

result = DateTime.ParseE xact("1999-12-01T23:59:59",
"yyyy-MM-ddTHH:mm:ss", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);
result = DateTime.ParseE xact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);

outputs:

01-12-1999 23:59:59
01-12-1999 18:59:59

Your post indicates that your time zone is 1 hour ahead of UTC which
means tht when it is 11:59:59 PM UTC then it is 12:59:59 AM the next day
in your time zone which is exactly the result you got.

To get the result you want, the format string should, as Arne points
out, be "yyyy-MM-ddTHH:mm:ssz", but your value string should be
"1999-12-01T23:59:59+0".
No.

result = DateTime.ParseE xact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);
result = DateTime.ParseE xact("1999-12-01T23:59:59+0",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);

outputs:

01-12-1999 23:59:59
01-12-1999 18:59:59

Arne
Nov 5 '07 #3
Yes. I seem what you mean.

I wonder if the Z is some sort of indicator included for the military who
use the term Zulu in place of UTC.
"Arne Vajhøj" <ar**@vajhoej.d kwrote in message
news:47******** *************** @news.sunsite.d k...
Stephany Young wrote:
>You specified 'Z' in the format string ("yyyy-MM-ddTHH:mm:ssZ") therefore
your value string MUST end with a 'Z' otherwise the call to
DateTime.Parse Exact will fail. ParseExact means just that (it must macth
EXACTLY).

The problem is that Z apperently do effect the parsing.

result = DateTime.ParseE xact("1999-12-01T23:59:59", "yyyy-MM-ddTHH:mm:ss",
CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);
result = DateTime.ParseE xact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);

outputs:

01-12-1999 23:59:59
01-12-1999 18:59:59

>Your post indicates that your time zone is 1 hour ahead of UTC which
means tht when it is 11:59:59 PM UTC then it is 12:59:59 AM the next day
in your time zone which is exactly the result you got.

To get the result you want, the format string should, as Arne points out,
be "yyyy-MM-ddTHH:mm:ssz", but your value string should be
"1999-12-01T23:59:59+0".

No.

result = DateTime.ParseE xact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);
result = DateTime.ParseE xact("1999-12-01T23:59:59+0",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.Inv ariantCulture);
Console.WriteLi ne(result);

outputs:

01-12-1999 23:59:59
01-12-1999 18:59:59

Arne
Nov 5 '07 #4
Stephany,

Zulu comes from Zero. I thought that military was only used in the USA, GMT
is at least in Europe more common for the official UTC. Have I understand it
well that the in my idea very Gemenebest country New Sealand uses as well
"Military"?

I don't by the way understand why Peter wants to get another date then he
has written.

In the very spread area CET it now (Not Summer Time) exactly one our later
then in UTC/GMT/ZULU/Military.

For your information: I wrote "spread area" this is because by instance the
Netherlands should be geographicaly in GMT. However (AFAIK) after the last
war they left it in CET because the whole western part of European continent
is now almost in it.

Cor

Nov 5 '07 #5
No Cor!

Zulu (UTC) comes from the last letter of the NATO phonetic alphabet, (Alpha,
Bravo, Charlie, ..., Xray, Yankee, Zulu).

It is the standard designator for the time base in aviation throughout the
world.

It's got absoulutely nothing to do with CET, the Netherlands, the
Commonwealth or even New Zealand for that matter.
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:5E******** *************** ***********@mic rosoft.com...
Stephany,

Zulu comes from Zero. I thought that military was only used in the USA,
GMT is at least in Europe more common for the official UTC. Have I
understand it well that the in my idea very Gemenebest country New Sealand
uses as well "Military"?

I don't by the way understand why Peter wants to get another date then he
has written.

In the very spread area CET it now (Not Summer Time) exactly one our later
then in UTC/GMT/ZULU/Military.

For your information: I wrote "spread area" this is because by instance
the Netherlands should be geographicaly in GMT. However (AFAIK) after the
last war they left it in CET because the whole western part of European
continent is now almost in it.

Cor
Nov 5 '07 #6
Stephany,

GMT/UTC/Militairy is Zero time, as you wrote it has to do with the phonetic
alphabet, however I thought, let I not write that to Stephany, because then
I get a correction.

It is created in Greenwich, there is a nice building that you can see when
you go from London upwards to where Jon Skeet is living at your right side.
That building is at the Zero time of the world.

:-)

Cor
Nov 5 '07 #7
Doh,

Not to the North, I meant upward sailing on the Thames,

Cor
Nov 5 '07 #8
Stephany,

And to make even three answers on your message.

The OP is from the CET timezone like me, and therefore his time is 1 hour
later then UTC/CET/Zulu/Zero/Military time.

My later part was as well meant for the OP.

Cor
Nov 5 '07 #9
Again Cor, do the research please!

CET is 1 hour AHEAD of UTC, not BEHIND.
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Stephany,

And to make even three answers on your message.

The OP is from the CET timezone like me, and therefore his time is 1 hour
later then UTC/CET/Zulu/Zero/Military time.

My later part was as well meant for the OP.

Cor
Nov 5 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3961
by: Mike Pemberton | last post by:
I'm sure there's a good explanation for this effect, but I get rather a strange output from this little test: #include <iostream> #include <list> int main() { std::list<int> int_list;
0
1603
by: Fred Strauss | last post by:
I am having an odd problem using the DateTime.ParseExact() method that I'm hoping someone can help me with. I have XML files that use 2 different date formats internally. I am trying to use the same call to ParseExact to parse either format. I am using C# to call the following form of ParseExact: public static DateTime ParseExact(string, string, IFormatProvider, DateTimeStyles);
3
7791
by: Dave P. | last post by:
I'm trying to parse a string into a DateTime object. I want to try using ParseExact to see if I can improve performance of a frequently-called method (i.e., please don't suggest using Parse()). My code looks like this: IFormatProvider fp = new System.Globalization.CultureInfo ("en-US"); DateTime dt = DateTime.ParseExact("Mar 9, 2005", "MMM d, yyyy", fp);
5
1748
by: ramon.smits | last post by:
I'm trying to get the following date/time string formatted. But I don't succeed. I get an exception saying the date/time string is invalid. string input = "8/09/05 9:27a"; string format = "M/dd/yy h:mmt"; DateTime.ParseExact(input, format, null); What am I doing wrong here? The following parse works ok.
11
7256
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
1
4463
by: Pablo | last post by:
Hello, I have big problem with method ParseExact from class DateTime. Here is code sample: '----------------------------------------------------------------------------------------------------------------------------------------- Module Module1 Sub Main() Console.WriteLine("Start...") Try
1
15036
by: Erica | last post by:
Hi. I have a string: "11/24/2006 23:59" named StartDateTime I need the string to be converted into a DateTime object in the following format: 2006-11-24 11:59 PM I tried the following: DateTime.ParseExact(StartDateTime,"yyyy-MM-dd HH:mm tt*", System.Globalization.CultureInfo.CurrentCulture)
3
21277
by: Peter Duniho | last post by:
I'm sure there's a good explanation for this, but I can't figure it out. I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance, in which I'd replaced the DateTimeFormatInfo.FullDateTimePattern property with my custom format string: DateTimeFormatInfo dtfi = (DateTimeFormatInfo)DateTimeFormatInfo.InvariantCulture.Clone(); dtfi.FullDateTimePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
5
5611
by: John B | last post by:
Hi all, Any idea why this code results in a FormatException? DateTime.ParseExact("40708", "dMMyy", CultureInfo.CurrentCulture) If I use "040708" with the same format string it works and it parses all double digit days fine. TIA JB
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.