在Go語言中,時間包提供了確定和查看時間的函數。 Go語言中的FixedZone()函數用於查找始終使用區域和偏移的規定名稱(即UTC以東的秒數)的位置。此外,此函數在時間包下定義。在這裏,您需要導入“time”包才能使用這些函數。
用法:
func FixedZone(name string, offset int) *Location
在這裏,“name”是區域的名稱,offset保留一個整數,* Location是指向該位置的指針。其中“Location”構成了使用中的時間偏移集。
返回值:它返回不斷使用指定的區域名稱和偏移量的位置。
範例1:
// Golang program to illustrate the usage of
// FixedZone() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Calling main
func main() {
// Calling FixedZone method
// with its parameter
location:= time.FixedZone("UTC-7", -7*50*50)
// Prints location
fmt.Println(location)
}
輸出:
UTC-7
在此,返回指定的位置。
範例2:
// Golang program to illustrate the usage of
// FixedZone() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Calling main
func main() {
// Calling FixedZone
// method with its parameters
location:= time.FixedZone("UTC-6", -6*40*40)
// Calling Date method
// with all its parameters
// that is date, time, and location
tm := time.Date(2020, time.April, 6,
9, 55, 06, 0, location)
// Prints date,
// time and location
fmt.Println(tm)
}
輸出:
2020-04-06 09:55:06 -0240 UTC-6
在這裏,首先調用FixedZone()方法,然後調用Date()方法及其參數,即日期,時間和位置,然後將所有這些參數作為輸出返回。
相關用法
- Golang math.Lgamma()用法及代碼示例
- Golang math.Float64bits()用法及代碼示例
- Golang atomic.AddInt64()用法及代碼示例
- Golang atomic.StoreInt64()用法及代碼示例
- Golang reflect.FieldByIndex()用法及代碼示例
- Golang string.Contains用法及代碼示例
- Golang bits.Sub()用法及代碼示例
- Golang io.PipeWriter.CloseWithError()用法及代碼示例
- Golang time.Round()用法及代碼示例
- Golang reflect.AppendSlice()用法及代碼示例
- Golang reflect.ChanOf()用法及代碼示例
- Golang flag.Bool()用法及代碼示例
- Golang time.Sleep()用法及代碼示例
- Golang time.Time.Year()用法及代碼示例
- Golang reflect.DeepEqual()用法及代碼示例
- Golang reflect.Indirect()用法及代碼示例
- Golang reflect.CanAddr()用法及代碼示例
- Golang reflect.CanInterface()用法及代碼示例
- Golang reflect.CanSet()用法及代碼示例
- Golang reflect.Cap()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 time.FixedZone() Function in Golang With Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。