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

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

如何將時(shí)區(qū)偏移量轉(zhuǎn)換為另一種格式

如何將時(shí)區(qū)偏移量轉(zhuǎn)換為另一種格式

Go
拉風(fēng)的咖菲貓 2022-07-11 17:19:03
我有一個(gè)沒(méi)有時(shí)區(qū)信息的時(shí)間戳。我需要以“+02:00”格式添加時(shí)區(qū)偏移量。那么在下面的代碼中,如何將偏移變量轉(zhuǎn)換為“+02:00”字符串以便獲得正確的 RFC3339 時(shí)間?func main() {    zone, offset := time.Now().Zone()    fmt.Println("zone :", zone)    fmt.Println("offset :", offset )    logtimestamp := "2020-11-14 05:53:40,103"    logtimestamp = strings.Split(logtimestamp, ",")[0]    logtimestampFields := strings.Fields(logtimestamp)    if len(logtimestampFields) > 1 {        logtimestamp = logtimestampFields[0] + "T" + logtimestampFields[1] + "+02:00" //replace "+02:00" with proper offset here    }        formattedTime, _ := time.Parse(time.RFC3339, logtimestamp)    fmt.Println("formatted timestamp " + formattedTime.Format(time.RFC3339))}
查看完整描述

1 回答

?
智慧大石

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

以下代碼應(yīng)該有所幫助。我已經(jīng)評(píng)論了代碼以便更好地理解。


package main


import (

    "fmt"

    "os"

    "time"

)


func main() {

    // Get the timezone

    zone, offset := time.Now().Zone()

    // Get the location

    var loc = time.FixedZone(zone, offset)

    // Reference format: Mon Jan 2 15:04:05 -0700 MST 2006

    t, err := time.ParseInLocation("2006-01-02 15:04:05", "2020-11-14 05:53:40", loc)

    if err != nil {

        fmt.Println("Error: ", err)

        os.Exit(1)

    }

    // Print the timestamp in RFC3339 format

    fmt.Println(t.Format(time.RFC3339))

}


查看完整回答
反對(duì) 回復(fù) 2022-07-11
  • 1 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報(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)