<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## time包 ### 時間格式化格式 ~~~ format := "2006-01-02 15:04:05" ~~~ ### 獲取當前時間 ~~~ now := time.Now() fmt.Println(now) //2024-02-29 11:3 4.41257 +0800 CST m=+0.000129751 //時間戳 timeStamp := now.Unix() fmt.Println(timeStamp) // 1709176339 fmt.Printf("%T \n", timeStamp) //int64 //毫秒、微妙、納秒 fmt.Println(now.UnixMilli(), now.UnixMicro(), now.UnixNano()) //1709176339194 1709176339194819 1709176339194819000 ~~~ ### 年月日時分秒、星期、一年的某天 ~~~ //獲取年月日 year,month,day := now.Date() //可以單獨獲取年月日 year1 := now.Year() month1 := now.Month() day1 := now.Day() //獲取時分秒 hour,minute,second := now.Clock() //可以單獨獲取時分秒 hour1 := now.Hour() minute1 := now.Minute() second1 := now.Second() //一年中的第幾天 yeadDay := now.YearDay() fmt.Println(yeadDay) //60 //一周中的第幾天 weekDay := now.Weekday() fmt.Println(weekDay) // Thursday 英語上的周一到周日 // 轉化數字 weekDayInt := int(weekDay) fmt.Println(weekDayInt) // 4 周日是0 范圍0-6 ~~~ ### 格式化時間 ~~~ now := time.Now() fmt.Println(now.Format("2006-01-02 15:03:04")) //2024-02-29 12:12:07 fmt.Println(now.Format("2006-01-02")) //2024-02-29 fmt.Println(now.Format("15:03:04")) //12:12:07 fmt.Println(now.Format("2006/01/02 15:04")) //2024/02/29 12:07 fmt.Println(now.Format("15:04 2006/01/02")) //12:07 2024/02/29 ~~~ ### 設置時區獲取時間 ~~~ //加載時區 loc, _ := time.LoadLocation("Asia/Shanghai") t, _ := time.ParseInLocation(format, nowTimeStr, loc) fmt.Println(now) //2024-02-29 11:49:17 +0800 CST ~~~ ### 指定時間返回 ~~~ local, _ := time.LoadLocation("Asia/Shanghai") //local := time.Local //分別指定年,月,日,時,分,秒,納秒,時區 onlyDay := time.Date(2024, 3, 3, 23, 0, 0, 0, local) ~~~ ### 設置時間大于24小時 ~~~ //分別指定年,月,日 ,可以設置負數 now := time.Now()//2024-02-29 11:49:17 +0800 CST addDate := now.AddDate(0,0,1); fmt.Println(addDate)//2024-03-01 11:49:17 +0800 CST ~~~ ### 設置時間小于24小時 ~~~ now := time.Now() //加法 1小時之后 later := now.Add(time.Hour) fmt.Println(now.Unix(), later.Unix()) //1709187802 1709191402 //減法 sub1 := later.Add(-time.Hour) sub2 := later.Sub(now) fmt.Println(sub1.Unix(), sub2) //1707740816 1h0m0s //判斷兩個時間是否相同,會考慮時區的影響,因此不同時區標準的時間也可以正確比較 isEqual := later.Equal(later) fmt.Println(isEqual) // true isAfer := later.After(now) fmt.Println(isAfer) // true isBefore := later.Before(now) fmt.Println(isBefore) // false //使用ParseDuration t1, _ := time.ParseDuration("13h4m5s") after2 := now.Add(t1) //2024-03-01 03:24:07.560044 +0800 CST m=+47045.000031876 ~~~ ### time.since ~~~ now := time.Now() time.Sleep(3 * time.Second)//睡眠3秒 dua := time.Since(now) // 可以用于統計代碼執行時長 3.00147325s fmt.Println(dua) ~~~ ### timer ~~~ tim := time.NewTimer(1 * time.Second) <-tim.C fmt.Println(time.Now().Unix()) tim.Stop() ~~~ ### ticker ~~~ //本質上是一個channel ticker := time.Tick(time.Second) //定義一個1秒間隔的定時器 for i := range ticker { fmt.Println(i) //每秒都會執行的任務 } ~~~ ## 封裝 ### 日期-->時間戳 調用時注意fmtStr與valueStr格式相同 ~~~ func Date2TimeStamp(fmtStr, valueStr, locStr string) int64 { loc := time.Local if locStr != "" { loc, _ = time.LoadLocation(locStr) // 設置時區 } if fmtStr == "" { fmtStr = "2006-01-02 15:04:05" //設置時間格式 } t, _ := time.ParseInLocation(fmtStr, valueStr, loc) return t.Unix() } ~~~ ### 時間戳-->日期 ~~~ func TimeStamp2Date(sec int64, fmtStr string) string { if fmtStr == "" { fmtStr = "2006-01-02 15:04:05" } return time.Unix(sec, 0).Format(fmtStr) } ~~~ ### 時間日期Time.time轉換 ![](https://img.kancloud.cn/f9/dd/f9dd2f2b263e41e52b9f511055b85894_1324x290.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看