1 Star 0 Fork 12

hlwqds / nsq

forked from Gitee 极速下载 / NSQ 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
strftime.go 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
Matt Reiferson 提交于 2013-08-27 23:51 . move examples to apps & bench
// COPIED FROM https://github.com/jehiah/go-strftime
package main
import (
"time"
)
// taken from time/format.go
var conversion = map[string]string{
/*stdLongMonth */ "B": "January",
/*stdMonth */ "b": "Jan",
// stdNumMonth */ "m": "1",
/*stdZeroMonth */ "m": "01",
/*stdLongWeekDay */ "A": "Monday",
/*stdWeekDay */ "a": "Mon",
// stdDay */ "d": "2",
// stdUnderDay */ "d": "_2",
/*stdZeroDay */ "d": "02",
/*stdHour */ "H": "15",
// stdHour12 */ "I": "3",
/*stdZeroHour12 */ "I": "03",
// stdMinute */ "M": "4",
/*stdZeroMinute */ "M": "04",
// stdSecond */ "S": "5",
/*stdZeroSecond */ "S": "05",
/*stdLongYear */ "Y": "2006",
/*stdYear */ "y": "06",
/*stdPM */ "p": "PM",
// stdpm */ "p": "pm",
/*stdTZ */ "Z": "MST",
// stdISO8601TZ */ "z": "Z0700", // prints Z for UTC
// stdISO8601ColonTZ */ "z": "Z07:00", // prints Z for UTC
/*stdNumTZ */ "z": "-0700", // always numeric
// stdNumShortTZ */ "b": "-07", // always numeric
// stdNumColonTZ */ "b": "-07:00", // always numeric
"%": "%",
}
// This is an alternative to time.Format because no one knows
// what date 040305 is supposed to create when used as a 'layout' string
// this takes standard strftime format options. For a complete list
// of format options see http://strftime.org/
func strftime(format string, t time.Time) string {
layout := ""
length := len(format)
for i := 0; i < length; i++ {
if format[i] == '%' && i <= length-2 {
if layoutCmd, ok := conversion[format[i+1:i+2]]; ok {
layout = layout + layoutCmd
i++
continue
}
}
layout = layout + format[i:i+1]
}
return t.Format(layout)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hlwqds/nsq.git
git@gitee.com:hlwqds/nsq.git
hlwqds
nsq
nsq
v0.3.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891