大佬教程收集整理的这篇文章主要介绍了golang timestamp,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
package @H_412_4@mmtime import ( @H_@R_801_11248@_9@"fmt" @H_@R_801_11248@_9@ "strconv" @H_@R_801_11248@_9@ "time" ) // FMT_TYPE_NOMAL const ( DATE_TIME_FMT = @H_@R_801_11248@_9@"2006-01-02 15:04:05" @H_@R_801_11248@_9@ @H_@R_801_11248@_9@ DATE_FMT = @H_@R_801_11248@_9@"2006-01-02" @H_@R_801_11248@_9@ @H_@R_801_11248@_9@ TIME_FMT = @H_@R_801_11248@_9@"15:04:05" @H_@R_801_11248@_9@ @H_@R_801_11248@_9@ DATE_TIME_FMT_CN = @H_@R_801_11248@_9@"2006年@H_@R_801_11248@_9@01月@H_@R_801_11248@_9@02日@H_@R_801_11248@_9@ 15时@H_@R_801_11248@_9@04分@H_@R_801_11248@_9@05秒@H_@R_801_11248@_9@" @H_@R_801_11248@_9@ @H_@R_801_11248@_9@ DATE_FMT_CN = @H_@R_801_11248@_9@"2006年@H_@R_801_11248@_9@01月@H_@R_801_11248@_9@02日@H_@R_801_11248@_9@" @H_@R_801_11248@_9@ @H_@R_801_11248@_9@ TIME_FMT_CN = @H_@R_801_11248@_9@"15时@H_@R_801_11248@_9@04分@H_@R_801_11248@_9@05秒@H_@R_801_11248@_9@" ) const SecondInNano = 1000 * 1000 * 1000 //return 1441006057 in sec func Gettimestamp() int64 { return time.Now().Unix() } //return 1441006057 in sec func GettimestampString() String { return strconv.FormaTint(Gettimestamp(),10) } // return 1441007112776 in millisecond func GettimestampInMilli() int64 { return int64(time.Now().UnixNano() / (1000 * 1000)) // ms } // return 1441007112776 in millisecond func GettimestampInMilliString() String { return strconv.FormaTint(GettimestampInMilli(),10) } //微秒 func GettimestampInMicro() int64 { return int64(time.Now().UnixNano() / 1000) // ms } // 微秒 func GettimestampInMicroString() { return strconv.FormaTint(GettimestampInMicro(),10) } //format func GetCurrentTimeFormat(format String) String { return GetTimeFormat(Gettimestamp(),format) } // func GetTimeFormat(second int64,format String) String { return time.Unix(second,0).Format(format) } // Timing the cost of function call,unix nano was returned func Elapse(f func()) int64 { now := time.Now().UnixNano() f() return time.Now().UnixNano() - now } // Timing the cost of function call,unix nano was returned func ElapseString(f func()) String { return strconv.FormaTint(Elapse(f),10) } // GetMonthDays return days of the month/year func GetMonthDays(year,@H_412_4@month int) int { switch @H_412_4@month { case 1,3,5,7,8,10,12: return 31 case 4,6,9,11: return 30 case 2: if IsLeapYear(year) { return 29 } return 28 default: panic(fmt.Sprintf(@H_@R_801_11248@_9@"Illegal month:%d",@H_412_4@month)) } } // IsLeapYear check whether a year is leay func IsLeapYear(year int) bool { if year%100 == 0 { return year%400 == 0 } return year%4 == 0 }
以上是大佬教程为你收集整理的golang timestamp全部内容,希望文章能够帮你解决golang timestamp所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。