locked
Getting date in RFC-822 format RRS feed

  • Question

  • User-999963490 posted

    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! 

    Saturday, June 14, 2008 7:44 AM

Answers

  • User1189110398 posted

    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 Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 23, 2008 5:32 PM

All replies

  • User-999963490 posted

    Anybody? 

    Saturday, June 14, 2008 8:16 PM
  • User1189110398 posted

    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 Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 23, 2008 5:32 PM
  • User-999963490 posted

    Great

    Thanks! 

    Monday, June 23, 2008 6:23 PM