|
-
Jan 26th, 2005, 09:29 PM
#1
Thread Starter
Addicted Member
VB.NET: Format Date......[Resolved]
Say i have these XML tag
Code:
<book published="New York">
<date day="12" month="1" year="2005" />
</book>
How do i exactly format the date since i am getting three different attributes (day, month and year) from the server......
Say i want the format to be "DD/MM/YYYY"...
I want the format date to be displayed in the listbox...
Does anyone have any idea to combined all three attributes and format instead of format directly the date as a whole....
Thanks
Last edited by toytoy; Jan 28th, 2005 at 12:06 PM.
-
Jan 27th, 2005, 12:10 AM
#2
I wonder how many charact
Re: VB.NET: Format Date
I believe your intention is to format the date your given for display in a listbox, correct?
Then you would probably want to implement a variation of the date formatting options available.
VB Code:
Dim day As String = "2"
Dim month As String = "9"
Dim year As String = "2002"
Dim tempDt As DateTime = New DateTime(Integer.Parse(year, CultureInfo.InvariantCulture), _
Integer.Parse(month, CultureInfo.InvariantCulture), Integer.Parse(day, CultureInfo.InvariantCulture))
MessageBox.Show(String.Format("{0}", tempDt.ToString("dd/MM/yyyy")))
-
Jan 27th, 2005, 01:03 AM
#3
Thread Starter
Addicted Member
Re: VB.NET: Format Date
where you got the CultureInfo....
I got error saying it is not declared..
-
Jan 27th, 2005, 01:03 AM
#4
Re: VB.NET: Format Date
What's wrong with simply using Date.Parse?
-
Jan 27th, 2005, 07:19 PM
#5
I wonder how many charact
Re: VB.NET: Format Date
You need to include an imports statement at the top of the class.
Imports System.Globalization
-
Jan 27th, 2005, 07:21 PM
#6
I wonder how many charact
Re: VB.NET: Format Date
 Originally Posted by mendhak
What's wrong with simply using Date.Parse?
There are apparently some logic holes in Date.Parse and we've been receiving about a dozen errors now and then on valid dates. We don't know for sure what's causing the errors, but constructing the Date object with integer values solved it. My guess is some users even in the US do not use the default US-EN culture format (immigrants?) on their systems.
-
Jan 28th, 2005, 04:12 AM
#7
Re: VB.NET: Format Date
Very interesting, this is making me think about all the places I have used it.
It just goes to show that everyone should adopt the US date format or be annhilated.
-
Jan 28th, 2005, 12:05 PM
#8
Thread Starter
Addicted Member
Re: VB.NET: Format Date
I use these few lines to solve it...
VB Code:
Dim niEuro As New System.Globalization.DateTimeFormatInfo
Dim dd, mm, yyyy, pa As String
dd = nod2.Attributes("day").Value
mm = nod2.Attributes("month").Value
yyyy = nod2.Attributes("year").Value
pa = dd & "/" & mm & "/" & yyyy
niEuro.ShortDatePattern = "dd/MM/yyyy"
Dim dataEuro As Date = Date.Parse(pa, niEuro)
MessageBox.Show(dataEuro)
but nemaroller, your solution is still the best..
Last edited by toytoy; Jan 28th, 2005 at 01:05 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|