You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1021 B
Go
35 lines
1021 B
Go
package timehelper_test
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// Javascript 只能精确到毫秒:
|
|
// new Date('2023-01-15T15:16:17.123456789+08:00').toISOString()
|
|
// Output: '2023-01-15T07:16:17.123Z'
|
|
func ExampleRFC3339Nano() {
|
|
t, _ := time.Parse(time.RFC3339Nano, "2023-01-15T15:16:17.123456789+08:00")
|
|
fmt.Println(t.Format(time.RFC3339Nano))
|
|
// Output: 2023-01-15T15:16:17.123456789+08:00
|
|
}
|
|
|
|
func ExampleRFC3339Nano2Sec() {
|
|
t, _ := time.Parse(time.RFC3339Nano, "2023-01-15T15:16:17.123456789+08:00")
|
|
fmt.Println(t.Format(time.RFC3339))
|
|
// Output: 2023-01-15T15:16:17+08:00
|
|
}
|
|
|
|
// 使用 RFC3339 没有丢失纳秒精度
|
|
func ExampleRFC3339Sec2Nano() {
|
|
t, _ := time.Parse(time.RFC3339, "2023-01-15T15:16:17.123456789+08:00")
|
|
fmt.Println(t.Format(time.RFC3339Nano))
|
|
// Output: 2023-01-15T15:16:17.123456789+08:00
|
|
}
|
|
|
|
func ExampleRFC3339NanoOtherZone() {
|
|
t, _ := time.Parse(time.RFC3339Nano, "2023-01-15T15:16:17.123456789+09:00")
|
|
fmt.Println(t.Format(time.RFC3339Nano))
|
|
// Output: 2023-01-15T15:16:17.123456789+09:00
|
|
}
|