Standard library / net/mail
mail.Header.Date()
Parse the Date header and return an error if it is missing or malformed. Expected stdout: '2024-01-02T03:04:05Z\n'.
Formal Syntax & Structure
go syntaxgo
func (h Header) Date() (time.Time, error)Return Value
(time.Time, error)
Parsed timestamp and error.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/mail" "strings" "time")
func main() { m := must(mail.ReadMessage(strings.NewReader("From: Ada <ada@example.invalid>\r\nSubject: demo\r\nDate: Tue, 02 Jan 2024 03:04:05 +0000\r\n\r\nhello"))) fmt.Println(must(m.Header.Date()).UTC().Format(time.RFC3339))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}