本文整理汇总了Golang中Time.Format函数的典型用法代码示例。如果您正苦于以下问题:Golang Format函数的具体用法?Golang Format怎么用?Golang Format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Rule
func (c *Context) Rule() (string, error) {
p := url.Values{}
time := c.runHistory.Start
p.Add("alert", c.Alert.Name)
p.Add("fromDate", time.Format("2006-01-02"))
p.Add("fromTime", time.Format("15:04"))
p.Add("template_group", c.Group.Tags())
return c.schedule.Conf.MakeLink("/config", &p), nil
}
示例2: Rule
func (c *Context) Rule() (string, error) {
p := url.Values{}
//There might be something better when we tie the notifications to evaluation time issue #395
time := time.Now().UTC()
p.Add("alert", c.Alert.Name)
p.Add("fromDate", time.Format("2006-01-02"))
p.Add("fromTime", time.Format("15:04"))
p.Add("template_group", c.Group.Tags())
return c.schedule.Conf.MakeLink("/config", &p), nil
}
示例3: SetItem
func (dm *DataManager) SetItem(i ItemRedis) {
con := dm.Get()
i.Id = dm.GetNewItemId()
time := GetFeedDateTime(i.PubDate)
itemkeyname := REDISKEY_FEED_ITEM_PREFIX + strconv.Itoa(i.Id)
con.Send("MULTI")
con.Send("SADD", REDISKEY_FEED_EXISTS, i.Link)
con.Send("ZADD", REDISKEY_FEED_TIME, time.Format(GetDateTimeFormat()), itemkeyname)
if len(i.Category) > 0 {
con.Send("ZADD", REDISKEY_FEED_TIME_PREFIX+i.Category, time.Format(GetDateTimeFormat()), itemkeyname)
}
con.Send("HMSET", redis.Args{itemkeyname}.AddFlat(i)...)
con.Send("EXPIREAT", itemkeyname, time.AddDate(0, 0, dm.UserConfig.Site.ItemExpire).Unix())
con.Do("EXEC")
}
示例4: standardDate
func (h HsbcLine) standardDate() string {
time, err := time.Parse("02/01/2006", h.Date)
if err != nil {
log.Fatal(err)
}
return time.Format("2006-01-02")
}
示例5: TransactionDate
func (t TdLine) TransactionDate() string {
time, err := time.Parse("02/01/2006", t.Date)
if err != nil {
log.Fatal(err)
}
return time.Format("2006-01-02")
}
示例6: SettlementDate
func (t TdLine) SettlementDate() string {
time, err := time.Parse("02/01/2006", t.SettlementDate_)
if err != nil {
log.Fatal(err)
}
return time.Format("2006-01-02")
}
示例7: TestFormatShortYear
func TestFormatShortYear(t *testing.T) {
years := []int{
-100001, -100000, -99999,
-10001, -10000, -9999,
-1001, -1000, -999,
-101, -100, -99,
-11, -10, -9,
-1, 0, 1,
9, 10, 11,
99, 100, 101,
999, 1000, 1001,
9999, 10000, 10001,
99999, 100000, 100001,
}
for _, y := range years {
time := Date(y, January, 1, 0, 0, 0, 0, UTC)
result := time.Format("2006.01.02")
var want string
if y < 0 {
// The 4 in %04d counts the - sign, so print -y instead
// and introduce our own - sign.
want = fmt.Sprintf("-%04d.%02d.%02d", -y, 1, 1)
} else {
want = fmt.Sprintf("%04d.%02d.%02d", y, 1, 1)
}
if result != want {
t.Errorf("(jan 1 %d).Format(\"2006.01.02\") = %q, want %q", y, result, want)
}
}
}
示例8: convertToItems
func convertToItems(channel *rss.Channel) ([]types.Item, error) {
items := make([]types.Item, len(channel.Item))
for i := 0; i < len(channel.Item); i++ {
from := channel.Item[i]
to := types.Item{}
to.Id = from.GUID
to.Title = from.Title
to.Description = html.UnescapeString(from.Description)
to.Content = from.Content
time, err := from.PubDate.Parse()
if err != nil {
to.Published = string(from.PubDate)
} else {
to.Published = time.Format(types.DateFormat)
}
if from.Enclosure.URL != "" {
to.Type = from.Enclosure.Type
to.Url = from.Enclosure.URL
} else {
to.Type = "Link"
to.Url = from.Link
}
items[i] = to
}
return items, nil
}
示例9: TestFormatSingleDigits
// issue 12440.
func TestFormatSingleDigits(t *testing.T) {
time := Date(2001, 2, 3, 4, 5, 6, 700000000, UTC)
test := FormatTest{"single digit format", "3:4:5", "4:5:6"}
result := time.Format(test.format)
if result != test.result {
t.Errorf("%s expected %q got %q", test.name, test.result, result)
}
}
示例10: TestFormat
func TestFormat(t *testing.T) {
// The numeric time represents Thu Feb 4 21:00:57.012345600 PST 2010
time := Unix(0, 1233810057012345600)
for _, test := range formatTests {
result := time.Format(test.format)
if result != test.result {
t.Errorf("%s expected %q got %q", test.name, test.result, result)
}
}
}
示例11: TestFormat
func TestFormat(t *testing.T) {
// The numeric time represents Thu Feb 4 21:00:57 PST 2010
time := SecondsToLocalTime(1233810057)
for _, test := range formatTests {
result := time.Format(test.format)
if result != test.result {
t.Errorf("%s expected %q got %q", test.name, test.result, result)
}
}
}
示例12: TestMissingZone
// Check that a time without a Zone still produces a (numeric) time zone
// when formatted with MST as a requested zone.
func TestMissingZone(t *testing.T) {
time, err := Parse(RubyDate, "Thu Feb 02 16:10:03 -0500 2006")
if err != nil {
t.Fatal("error parsing date:", err)
}
expect := "Thu Feb 2 16:10:03 -0500 2006" // -0500 not EST
str := time.Format(UnixDate) // uses MST as its time zone
if str != expect {
t.Errorf("got %s; expect %s", str, expect)
}
}
示例13: main
func main() {
value := "04/19/1979" // my birthday
parseFormat := "01/02/2006"
// parse the string into a time object
time, _ := time.Parse(parseFormat, value)
printFormat := "02.01.2006"
// and print it with the desired format
fmt.Println(time.Format(printFormat))
}
示例14: main
func main() {
flag.Parse()
srcDir, err := os.Open(*src)
if os.IsNotExist(err) {
log.Fatalf("Directory '%v' does not exist: %v", *src, err)
}
files, err := srcDir.Readdir(-1)
if err != nil {
log.Fatalf("Error occured on reading '%v': %v", *src, err)
}
for _, f := range files {
var ext string
switch {
case strings.HasSuffix(f.Name(), ".mp3"):
ext = ".mp3"
case strings.HasSuffix(f.Name(), ".m4a"):
ext = ".m4a"
default:
continue
}
index := strings.LastIndex(f.Name(), ".")
base := f.Name()[0:index]
oldpath := filepath.Join(*src, f.Name())
// file base name should be "YYYYmmdd-NNN"
matched, err := regexp.MatchString(`\d{8}\-\d{3,4}`, base)
if err != nil || !matched {
continue
}
elements := strings.Split(base, "-")
dateStr := elements[0]
numberStr := elements[1]
time, err := time.Parse("20060102", dateStr)
if err != nil {
log.Printf("Error occured to read date '%v': %v", dateStr, err)
continue
}
filename := time.Format("伊集院光 深夜の馬鹿力 2006年01月02日") + " 第" + numberStr + "回" + ext
newpath := filepath.Join(*src, filename)
if err := os.Rename(oldpath, newpath); err != nil {
log.Printf("Error on renaming '%v' -> '%v'", oldpath, newpath)
}
}
}
示例15: MStoTimecode
// Function responsible for converting an integer of milliseconds to a timestamp
func MStoTimecode(milliseconds int) string {
// Creates a zeroed out time object that we will add our duration to
zero := new(time.Time)
// Parses the integer passed
duration, err := time.ParseDuration(strconv.Itoa(milliseconds) + "ms")
if err != nil {
return "00:00:00.000"
}
// Adds the duration to the zero time
time := zero.Add(duration)
// Returns the timestamp representation of our duration
return time.Format("15:04:05.000")
}