]> Cypherpunks repositories - gostls13.git/commitdiff
net/mail: add example for ParseDate
authorcuishuang <imcusg@gmail.com>
Wed, 9 Oct 2024 03:23:11 +0000 (11:23 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 9 Oct 2024 20:12:00 +0000 (20:12 +0000)
Change-Id: Id22d199ea4b0a9795dc3d9e5f7a74be13ff0cf58
Reviewed-on: https://go-review.googlesource.com/c/go/+/618755
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/net/mail/example_test.go

index d325dc791f9319cc21c0b390b713a49d4423bc5c..9fadda2463abe056c01b10c99428d61ed3ee154b 100644 (file)
@@ -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
+}