Standard library / net/mail
mail.ParseDate()
Parse a message date with its time zone. Convert to UTC when comparing timestamps. Expected stdout: '2024-01-02T01:04:05Z\n'.
Formal Syntax & Structure
go syntaxgo
func ParseDate(date string) (time.Time, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| date | string | RFC 5322 date text including time zone. |
Return Value
(time.Time, error)
Parsed timestamp and error.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/mail" "time")
func main() { t := must(mail.ParseDate("Tue, 02 Jan 2024 03:04:05 +0200")) fmt.Println(t.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) }}