473,382 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Unexpected result using DateTime.ParseExact

Hi,

I've the following line of code:

result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ",
CultureInfo.InvariantCulture);

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 9774
Peter Holschbach wrote:
I've the following line of code:

result = DateTime.ParseExact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ",
CultureInfo.InvariantCulture);

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.ParseExact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);

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.ParseExact will fail. ParseExact means just that (it must macth
EXACTLY).
The problem is that Z apperently do effect the parsing.

result = DateTime.ParseExact("1999-12-01T23:59:59",
"yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
Console.WriteLine(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.ParseExact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59+0",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(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.dkwrote in message
news:47***********************@news.sunsite.dk...
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.ParseExact will fail. ParseExact means just that (it must macth
EXACTLY).

The problem is that Z apperently do effect the parsing.

result = DateTime.ParseExact("1999-12-01T23:59:59", "yyyy-MM-ddTHH:mm:ss",
CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59Z",
"yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
Console.WriteLine(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.ParseExact("1999-12-01T23:59:59-5",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(result);
result = DateTime.ParseExact("1999-12-01T23:59:59+0",
"yyyy-MM-ddTHH:mm:ssz", CultureInfo.InvariantCulture);
Console.WriteLine(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**********************************@microsof t.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****************@TK2MSFTNGP05.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
Hi Stephany,

It is now 19:00 in the Netherlands which is as I wrote in CET and that is
one hour later then in England where it is 18:00.

(It is however earlier 12:00 here then in England, because CET is 1 hour
before GMT, that is probably your confusion, however I wrote nowhere that
CET is behind GMT/UTC/ZULU/Zero time/Military).

BBC 1 and 2 are standard television stations here and I can assure you that
I don't have to think when they are talking about the time and that is
forever because in the EU is the summertime (what is in the US timesaving
time) synchronized for every timetable.

Cor
Nov 5 '07 #11
Hi All,

thank you very much for all the answers (really a interesting thread and
helpful !!!).
Someone asked why to hell I didn't want to have the right result :-)

1) I have to support a application which stores the time informatin wrong
(ends with Zulu but local time is stored)
2) looking into the help for DateTime.FormatExact I could not find why the
function behaves as it does.

I asked the same question in the german NG and got an answer with many links
concerning this problem.
Maybe they are helpfule for you too. Here they are:

<http://msdn2.microsoft.com/en-us/library/91hfhz89.aspx>
<http://msdn2.microsoft.com/en-us/netframework/aa569606.aspx>
<http://msdn2.microsoft.com/en-us/library/ms973825.aspx>
<http://msdn2.microsoft.com/en-us/library/2h3syy57.aspx>
<http://msdn2.microsoft.com/en-us/library/5hh873ya.aspx>
<http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx>

<http://blogs.msdn.com/bclteam/archive/2004/12/20/327702.aspx>

<URL:http://blogs.msdn.com/bclteam/archiv...ony-moore.aspx
<http://blogs.msdn.com/bclteam/archive/2007/06/18/a-brief-history-of-datetime-anthony-moore.aspx>>
<URL:http://blogs.msdn.com/bclteam/archiv...ony-moore.aspx
<http://blogs.msdn.com/bclteam/archive/2007/07/12/a-brief-history-of-datetime-follow-up-anthony-moore.aspx>>

Peter
"Cor Ligthert[MVP]" <no************@planet.nlschrieb im Newsbeitrag
news:6D**********************************@microsof t.com...
Hi Stephany,

It is now 19:00 in the Netherlands which is as I wrote in CET and that is
one hour later then in England where it is 18:00.

(It is however earlier 12:00 here then in England, because CET is 1 hour
before GMT, that is probably your confusion, however I wrote nowhere that
CET is behind GMT/UTC/ZULU/Zero time/Military).

BBC 1 and 2 are standard television stations here and I can assure you
that I don't have to think when they are talking about the time and that
is forever because in the EU is the summertime (what is in the US
timesaving time) synchronized for every timetable.

Cor

Nov 5 '07 #12

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

Similar topics

3
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
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...
3
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()). ...
5
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 =...
11
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...
1
by: Pablo | last post by:
Hello, I have big problem with method ParseExact from class DateTime. Here is code sample: ...
1
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:...
3
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.