GO語言"time"包中"ParseInLocation"函數的用法及代碼示例。
用法:
func ParseInLocation(layout, value string, loc *Location)(Time, error)
ParseInLocation 與 Parse 類似,但在兩個重要方麵有所不同。首先,在沒有時區信息的情況下,Parse 將時間解釋為 UTC; ParseInLocation 將時間解釋為給定位置。其次,當給定區域偏移量或縮寫時,Parse 會嘗試將其與本地位置進行匹配; ParseInLocation 使用給定的位置。
例子:
package main
import (
"fmt"
"time"
)
func main() {
loc, _ := time.LoadLocation("Europe/Berlin")
// This will look for the name CEST in the Europe/Berlin time zone.
const longForm = "Jan 2, 2006 at 3:04pm (MST)"
t, _ := time.ParseInLocation(longForm, "Jul 9, 2012 at 5:02am (CEST)", loc)
fmt.Println(t)
// Note: without explicit zone, returns time in given location.
const shortForm = "2006-Jan-02"
t, _ = time.ParseInLocation(shortForm, "2012-Jul-09", loc)
fmt.Println(t)
}
輸出:
2012-07-09 05:02:00 +0200 CEST 2012-07-09 00:00:00 +0200 CEST
相關用法
- GO ParseInt用法及代碼示例
- GO ParseIP用法及代碼示例
- GO ParseAddress用法及代碼示例
- GO ParseUint用法及代碼示例
- GO ParseMediaType用法及代碼示例
- GO ParseCIDR用法及代碼示例
- GO ParseDuration用法及代碼示例
- GO ParseFile用法及代碼示例
- GO Parse用法及代碼示例
- GO ParseAddressList用法及代碼示例
- GO ParseBool用法及代碼示例
- GO ParseQuery用法及代碼示例
- GO ParseFloat用法及代碼示例
- GO ParsePKIXPublicKey用法及代碼示例
- GO PathUnescape用法及代碼示例
- GO PathEscape用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO PlainAuth用法及代碼示例
- GO Print用法及代碼示例
- GO Pow10用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 ParseInLocation。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。