本文整理汇总了Golang中Time.Time.AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.AppendFormat方法的具体用法?Golang Time.AppendFormat怎么用?Golang Time.AppendFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.AppendFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: formatTs
// formatTs formats t with an optional offset into a format lib/pq understands,
// appending to the provided tmp buffer and reallocating if needed. The function
// will then return the resulting buffer. formatTs is mostly cribbed from
// github.com/lib/pq.
func formatTs(t time.Time, offset *time.Location, tmp []byte) (b []byte) {
// Need to send dates before 0001 A.D. with " BC" suffix, instead of the
// minus sign preferred by Go.
// Beware, "0000" in ISO is "1 BC", "-0001" is "2 BC" and so on
if offset != nil {
t = t.In(offset)
} else {
t = t.UTC()
}
bc := false
if t.Year() <= 0 {
// flip year sign, and add 1, e.g: "0" will be "1", and "-10" will be "11"
t = t.AddDate((-t.Year())*2+1, 0, 0)
bc = true
}
if offset != nil {
b = t.AppendFormat(tmp, pgTimeStampFormat)
} else {
b = t.AppendFormat(tmp, pgTimeStampFormatNoOffset)
}
if bc {
b = append(b, " BC"...)
}
return b
}
示例2: addTime
func (enc *textEncoder) addTime(final *textEncoder, t time.Time) {
if enc.timeFmt == "" {
return
}
final.bytes = append(final.bytes, ' ')
final.bytes = t.AppendFormat(final.bytes, enc.timeFmt)
}
示例3: addTimestamp
func addTimestamp(b []byte, t time.Time) []byte {
if t.IsZero() {
b = append(b, nilValueByte)
} else {
b = t.AppendFormat(b, time.RFC3339Nano)
}
b = append(b, spaceByte)
return b
}