From 93166e29d3c6d9fc7e7ee352b1b6f5ca31425a4f Mon Sep 17 00:00:00 2001 From: cuishuang Date: Wed, 9 Oct 2024 11:23:11 +0800 Subject: [PATCH] net/mail: add example for ParseDate Change-Id: Id22d199ea4b0a9795dc3d9e5f7a74be13ff0cf58 Reviewed-on: https://go-review.googlesource.com/c/go/+/618755 Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/net/mail/example_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/net/mail/example_test.go b/src/net/mail/example_test.go index d325dc791f..9fadda2463 100644 --- a/src/net/mail/example_test.go +++ b/src/net/mail/example_test.go @@ -10,6 +10,7 @@ import ( "log" "net/mail" "strings" + "time" ) func ExampleParseAddressList() { @@ -75,3 +76,17 @@ Message body // Subject: Gophers at Gophercon // Message body } + +func ExampleParseDate() { + dateStr := "Wed, 09 Oct 2024 09:55:06 -0700" + + t, err := mail.ParseDate(dateStr) + if err != nil { + log.Fatalf("Failed to parse date: %v", err) + } + + fmt.Println(t.Format(time.RFC3339)) + + // Output: + // 2024-10-09T09:55:06-07:00 +}