All you have to call is the GetRFC822 Function with a datetime specified.
ie GetRFC822(Datetime.Now)
Function GetRFC822(ByVal dt As DateTime) As String
'ie: Sat 14 Jun 2008 07:43:35 EST
Return String.Format("{0} {1} {2} {3} {4}:{5}:{6} {7}", _
Left(dt.DayOfWeek.ToString, 3), dt.Day, GetMonth(dt.Month), _
dt.Year, dt.Hour.ToString.PadLeft(2, "0"), _
dt.Minute.ToString.PadLeft(2, "0"), _
dt.Second.ToString.PadLeft(2, "0"), GetTimeZone)
End Function
Private Function GetTimeZone() As String
Dim str As New Text.StringBuilder
Dim tz() As String = TimeZone.CurrentTimeZone.StandardName.Split(" ")
For i As Integer = 0 To UBound(tz)
str.Append(Left(tz(i), 1))
Next
Return str.ToString
End Function
Private Function GetMonth(ByVal month As Integer) As String
Select Case month
Case 1
Return "Jan"
Case 2
Return "Feb"
Case 3
Return "Mar"
Case 4
Return "Apr"
Case 5
Return "May"
Case 6
Return "Jun"
Case 7
Return "Jul"
Case 8
Return "Aug"
Case 9
Return "Sep"
Case 10
Return "Oct"
Case 11
Return "Nov"
Case 12
Return "Dec"
Case Else
Return ""
End Select
End Function
Marked as answer by drocco on Jun 23, 2008 10:23 PM
drocco
Member
596 Points
566 Posts
Getting date in RFC-822 format
Jun 14, 2008 11:44 AM|LINK
I'm making a page that allows the user to submit an entry to a blog by adding the item to an XML document
When the user submits the new entry, aside from the title and content, I want the date to be added to the item inside of my "date" element
I want the date to be in RFC-822 format, ie: Sat 14 Jun 2008 07:43:35 EST
How can I do this in the code behind?
Thanks!
drocco
Member
596 Points
566 Posts
Re: Getting date in RFC-822 format
Jun 15, 2008 12:16 AM|LINK
Anybody?
stlarmon
Participant
895 Points
156 Posts
Re: Getting date in RFC-822 format
Jun 23, 2008 09:32 PM|LINK
All you have to call is the GetRFC822 Function with a datetime specified.
ie GetRFC822(Datetime.Now)
Function GetRFC822(ByVal dt As DateTime) As String 'ie: Sat 14 Jun 2008 07:43:35 EST Return String.Format("{0} {1} {2} {3} {4}:{5}:{6} {7}", _ Left(dt.DayOfWeek.ToString, 3), dt.Day, GetMonth(dt.Month), _ dt.Year, dt.Hour.ToString.PadLeft(2, "0"), _ dt.Minute.ToString.PadLeft(2, "0"), _ dt.Second.ToString.PadLeft(2, "0"), GetTimeZone) End Function Private Function GetTimeZone() As String Dim str As New Text.StringBuilder Dim tz() As String = TimeZone.CurrentTimeZone.StandardName.Split(" ") For i As Integer = 0 To UBound(tz) str.Append(Left(tz(i), 1)) Next Return str.ToString End Function Private Function GetMonth(ByVal month As Integer) As String Select Case month Case 1 Return "Jan" Case 2 Return "Feb" Case 3 Return "Mar" Case 4 Return "Apr" Case 5 Return "May" Case 6 Return "Jun" Case 7 Return "Jul" Case 8 Return "Aug" Case 9 Return "Sep" Case 10 Return "Oct" Case 11 Return "Nov" Case 12 Return "Dec" Case Else Return "" End Select End Functiondrocco
Member
596 Points
566 Posts
Re: Getting date in RFC-822 format
Jun 23, 2008 10:23 PM|LINK
Great
Thanks!