Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString & " <<--Error")
debug output - a correct statement
12:00:00 PM <<--Error
0002, is the lonliest number... apologies to Three Dog Night
Last edited by dbasnett; Mar 5th, 2008 at 04:42 PM.
What are you looking for as far as the output is concerned? I ran this code and got the correct result.
The Convert.ToDateTime() function is using a 24-Hour clock. So, if you want 12:00 AM the code would be:
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("00:00:00")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString & " <<--Error")
Or, you can also write it as:
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00 AM")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString & " <<--Error")
Either of these examples will give you a result of 12:00 AM
and please I won't. To tell the truth it should say error here
TestTime = Convert.ToDateTime("12:00:00")
Since there was a discussion about whether 0002 was number or not, I thought I would bring this up.
Simply put, 12AM / 12PM and relatives (12:00:00 AM / 12:00:00 PM) are nonsense. I acknowledge that a lot of people know what is meant by that, but I am not one of them.
yeah, as VisualAd says, its all based on your PC settings...
Lots of countries use , instead of . with numbers
1,000,000.50
1.000.000,50
Or dates are written
03/05/2008
05/03/2008
If you don't know what culture you are using, then it is impossible to know if the date is march 5th, or may 3rd. However based on the culture, there are rules that govern the correct order of things.
What are you looking for as far as the output is concerned? I ran this code and got the correct result.
The Convert.ToDateTime() function is using a 24-Hour clock. So, if you want 12:00 AM the code would be:
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("00:00:00")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString & " <<--Error")
Or, you can also write it as:
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00 AM")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString & " <<--Error")
Either of these examples will give you a result of 12:00 AM
google, google, google. --->> noon midnight PM AM
You said "I ran this code and got the correct result." I think you ran the code and got an answer you expected.
yeah, as VisualAd says, its all based on your PC settings...
Lots of countries use , instead of . with numbers
1,000,000.50
1.000.000,50
Or dates are written
03/05/2008
05/03/2008
If you don't know what culture you are using, then it is impossible to know if the date is march 5th, or may 3rd. However based on the culture, there are rules that govern the correct order of things.
But don't I have a right for the result to be correct for my regional settings.
Like I said, in the spirit of 002, I brought this up. I don't deal with this. I always use military time (wonder why they do) and get clarifiaction if we are going to meet at 12AM / 12PM. It is just sad that Microsoft can't tell time.
dbasnett is referring to the fact that while there is a common understanding of what 12:00:00 AM means, to be extremely picky it is technically not valid (it should be "midnight"), but 12:00:01 AM is valid for a second later.
Either of these would be better, but not definitive.
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00 Noon")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString)
debug output -> 12:00:00 Noon
or
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00 Midnight")
Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
Debug.WriteLine(TestString)
debug output -> 12:00:00 Midnight
If I say lets meet at 12PM March 5th, when do I want to meet? At the boundary between march 5 - 6 or 4 - 5?
In theory it makes sense. But think of it this way as well:
1 nanosecond past midnight would make it AM and one nanosecond past noon would make it PM.
From a programming perspective, I would have to say that the answer that the application gives is correct. Trying to determine that the precise moment in time is exactly 00:00:00 or 12:00:00 is a little beyond what is expected.
it all comes down to culture.... the American culture uses AM/PM. So if you pick USA when you installed windows when it asks for your region, you get AM/PM time.
If you live in some other country where they don't use AM/PM, then you would have picked that country, and the regional settings would be set accordingly, never showing you AM or PM for times because you don't know what they mean.
And if you live in America, and you don't know what AM and PM are in terms of time, then the school system failed horribly.
You can of course customize Windows to display the date/time however you want.
If it isn't obvious I have thought about this before. My issue is an American issue, and one that I have resolved for myself through the use of military time.
Sorry that I thought it might be fun to discuss this here, it isn't. I'm done.
"And if you live in America, and you don't know what AM and PM are in terms of time, then the school system failed horribly." What does that mean?
Are you speaking generally or in the particular case of 12AM / 12PM? If in general I wasn't failed, I know the difference between 1AM / 1PM. If, as I am guessing, you mean 12AM / 12PM maybe it isn't my school that failed. Could it be that the schools I attended knew that 12AM / 12PM were incorrect?
For the record, it was my 9th grade Geometry teacher that started this. It was during a time when accepted did not mean right(Civil Rights). Maybe you read about it in History class.
FYI - I submitted this to MSDN as a Suggestion. My instinct tells me it will be ignored by Microsoft.
Last edited by dbasnett; Mar 6th, 2008 at 10:41 AM.
To display it as military time, you need to use capital H's in the format:
Code:
Dim TestTime As DateTime
TestTime = Convert.ToDateTime("12:00:00")
Dim TestString As String = String.Format("{0:HH:mm}", TestTime)
Debug.WriteLine(TestString & " <<--Error")