Datetime Custom format - Show AM / PM as uppercase letters, not am / pm

I have stringone that contains: December 14, 2011 9:45 am (note that "AM" is not uppercase ")

Now I wanted to create a variable with it datetime.

I tried to look, but this is the opposite of what I wanted. I also tried this one but could not. I have tried so far the following:

Dim dateNow As DateTime
Dim out As String = "14 Dec 2011 9:45 am"
dateNow = DateTime.ParseExact(out, "d MMM yyyy HH:mm tt", Nothing)

But, unfortunately, this does not work. Any ideas? Thank you VB.net Or C # code will be fine ..

+3
source share
3 answers

, H HH, datetime. 09 , HH . h 12 AM PM, Capital H 24 , 1:28 PM 13:28 PM

dateNow = DateTime.ParseExact(out, "d MMM yyyy h:mm tt", Nothing)

abut , .

enter image description here

DataTime .

+6

14 Dec 2011 09:45 am add 0 9.

Dim dateNow As DateTime
Dim out As String = "14 Dec 2011 09:45 am"
dateNow = DateTime.ParseExact(out, "dd MMM yyyy HH:mm tt", Nothing)

+2

:

    Dim dateNow As DateTime
    Dim out As String = "14 Dec 2011 12:45 am"
    Dim allowedFormats() As String = {"d MMM yyyy h:mm tt", "dd MMM yyyy h:mm tt", "d MMM yyyy hh:mm tt", "dd MMM yyyy hh:mm tt"}
    dateNow = DateTime.ParseExact(out, allowedFormats, Nothing, Globalization.DateTimeStyles.None)
0

All Articles