第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將 `2022-11-20 21:00:00+0900` 格式化為 IST

如何將 `2022-11-20 21:00:00+0900` 格式化為 IST

Go
紅糖糍粑 2023-03-15 14:49:54
我有一個(gè)時(shí)間戳,2022-11-20 21:00:00+0900現(xiàn)在我需要將其轉(zhuǎn)換為 IST。所以我試過(guò)了    loc, _ := time.LoadLocation("Asia/Calcutta")    format := "Jan _2 2006 3:04:05 PM"    timestamp := "2022-11-20 21:00:00+0900"    ISTformat, err := time.ParseInLocation(format, timestamp,  loc)    fmt.Println(ISTformat, err)但它沒(méi)有工作并給出錯(cuò)誤cannot parse我需要使用哪種類型的 golang 時(shí)間格式來(lái)執(zhí)行此操作?
查看完整描述

2 回答

?
飲歌長(zhǎng)嘯

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試以下


    loc, _ := time.LoadLocation("Asia/Calcutta")

    format := "2006-01-02 15:04:05-0700"

    timestamp := "2022-11-20 21:00:00+0900"

    // ISTformat, _ := time.ParseInLocation(format, timestamp, loc)

    // fmt.Println(ISTformat)

    parsed_time, _ := time.Parse(format, timestamp)

    IST_time := parsed_time.In(loc)

    fmt.Println("Time in IST", IST_time)

請(qǐng)注意,您的format和timestamp應(yīng)該采用相同的時(shí)間格式


查看完整回答
反對(duì) 回復(fù) 2023-03-15
?
滄海一幻覺(jué)

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

ParseInLocation 類似于 Parse,但在兩個(gè)重要方面有所不同。首先,在沒(méi)有時(shí)區(qū)信息的情況下,Parse 將時(shí)間解釋為 UTC;ParseInLocation 將時(shí)間解釋為給定位置。其次,當(dāng)給定區(qū)域偏移量或縮寫時(shí),Parse 會(huì)嘗試將其與本地位置進(jìn)行匹配;ParseInLocation 使用給定的位置。


**ParseInLocation 的格式是 ** func ParseInLocation(layout, value string, loc *Location) (Time, error)


你試試這個(gè)例子


package main


import (

? ? "fmt"

? ? "time"

)


func main() {

? ? loc, _ := time.LoadLocation("Asia/Calcutta")


? ? // This will look for the name CEST in the Asia/Calcutta 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)

? ? return

}


查看完整回答
反對(duì) 回復(fù) 2023-03-15
  • 2 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)