OutPutDateFormat string } // AddDuration 时间字符串加减天 // dateStr 是输入的时间字符串 // n 天数(负数为减,正数为加) func(t *TimeStrConverter) AddDuration(dateStr string, n int) (string, error) { // 1. 将dateStr按指定格式转换成时间 endDate, err := time.Parse(t.InputDateFormat, ...
fmt.Println(util.FormatDate(time.Now(), util.YYYY_MM_DD_EN)) fmt.Println(util.FormatDate(time.Now(), util.YYYY_MM_DD_HH_MM)) fmt.Println(util.FormatDate(time.Now(), util.YYYY_MM_DD_HH_MM_CN)) fmt.Println(util.FormatDate(time.Now(), util.YYYY_MM_DD_HH_MM_EN)) fmt.Println...
1、gotool.DateUtil.FormatToString 时间格式化成字符串 代码语言:txt AI代码解释 func TestFormatToString(t *testing.T) { now := gotool.DateUtil.Now() toString := gotool.DateUtil.FormatToString(&now, "YYYY-MM-DD hh:mm:ss") fmt.Println(toString) toString = gotool.DateUtil.FormatToString(&n...
fmt.Println("Short date:", now.Format("Jan 2, 2006")) fmt.Println("Long date:", now.Format("Mon Jan 2 15:04:05 2006")) } We get the current datetime withtime.Nowfunction and format it in three ways utilizing theFormatfunction. $ go run main.go Time: 18:10:34 Short date: Ma...
1) 时间戳转时间字符串 (int64 —> string) 代码语言:javascript 代码运行次数:0 运行 AI代码解释 timeUnix:=time.Now().Unix()//已知的时间戳formatTimeStr:=time.Unix(timeUnix,0).Format("2006-01-02 15:04:05")fmt.Println(formatTimeStr)//打印结果:2017-04-11 13:30:39 ...
timeStamp := time.Date(2021, 11, 20, 23, 34, 10, 0, time.Local).Unix() fmt.Println(timeStamp) } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 示例:获取当天01:00:00的时间戳 package main import ( "fmt" "time" ) func main() { ...
fmt.Println(t.Format(layout)) 1. 2. 3. 4. 1.根据指定时间返回 time.Time 类型,使用函数 time.Date() now := time.Now() layout := "2006-01-02 15:04:05" //根据指定时间返回 time.Time 类型 //分别指定年,月,日,时,分,秒,纳秒,时区 ...
func (t Time) String() string { return time.Time(t).Format(timeFormart) } type Person struct { Id int64 `json:"id"` Name string `json:"name"` Birthday Time `json:"birthday"` } 这种时间重定义了时间类型time.Time为Time类型,所以在结构体使用的时候要注意不要用错,结构体直接调用json的解析...
words := []string{"你好", "世界", "Go"} sentence := strings.Join(words, ",") fmt.Println(sentence) // 输出: 你好,世界,Go 在这个例子中,strings.Join正确地将三个中文单词连接成了一个完整的句子,并在每两个单词之间插入了中文逗号。这表明strings.Join不仅适用于ASCII字符,还能够处理各种语言的...
date,_ := Parse("2006-01-02","2019-05-01") date.Year(2008).Month(10).Day(30).Hour(11).Minute( 3).Second(12) fmt.Println(date.Format("2006-01-02 15:04:05")) //2008-10-30 11:03:12 The string formatting methods are similar tocarbon's string formatting ...