当前位置: 首页>>代码示例>>Golang>>正文


Golang Time.YearDay方法代码示例

本文整理汇总了Golang中Time.Time.YearDay方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.YearDay方法的具体用法?Golang Time.YearDay怎么用?Golang Time.YearDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Time.Time的用法示例。


在下文中一共展示了Time.YearDay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: convertTimeFormat

func convertTimeFormat(t time.Time, n byte) string {
	switch n {
	case 'a':
		return t.Weekday().String()[:3]
	case 'A':
		return t.Weekday().String()
	case 'b':
		return t.Month().String()[:3]
	case 'B':
		return t.Month().String()
	case 'c':
		return t.Format("ANSIC")
	case 'd':
		return fmt.Sprintf("%02d", t.Day())
	case 'H':
		return fmt.Sprintf("%02d", t.Hour())
	case 'I':
		hr := t.Hour() % 12
		if hr == 0 {
			hr = 12
		}
		return fmt.Sprintf("%02d", hr)
	case 'm':
		return fmt.Sprintf("%02d", t.Month())
	case 'M':
		return fmt.Sprintf("%02d", t.Minute())
	case 'p':
		if t.Hour() > 11 {
			return "PM"
		}
		return "AM"
	case 'S':
		return fmt.Sprintf("%02d", t.Second())
	case 'x':
		return t.Format("Mon Jan 02")
	case 'X':
		return t.Format("15:04:05")
	case 'y':
		year := fmt.Sprintf("%04d", t.Year())
		if l := len(year); l > 2 {
			return year[l-2 : l]
		}
		return year
	case 'Y':
		return fmt.Sprintf("%04d", t.Year())
	case 'j':
		return fmt.Sprintf("%02d", t.YearDay())
	case 'w':
		return fmt.Sprintf("%02d", t.Weekday())
	case 'U':
		_, w := t.ISOWeek()
		return fmt.Sprintf("%02d", w)
	case 'W':
		_, w := t.ISOWeek()
		return fmt.Sprintf("%02d", w)
	default:
		return string(n)
	}
}
开发者ID:get3w,项目名称:get3w,代码行数:59,代码来源:date.go

示例2: History

// History
func (h *Hound) History() {

	eventsSlices := h.getHistoryEvents()
	events := make([]*Event, 0)
	for _, eventsSlice := range eventsSlices {
		for _, event := range eventsSlice {
			events = append(events, event)
		}
	}

	sort.Sort(ByDate{events})

	now := time.Now()
	currentDay := new(time.Time)

	re := regexp.MustCompile(" +")

	for _, event := range events {
		if event.On.YearDay() != currentDay.YearDay() {
			var dateStr string
			if event.On.YearDay() == now.YearDay() {
				dateStr = "Today"
			} else {
				dateStr = event.On.Format("Monday 02 January")
			}
			fmt.Printf(sgr.MustParseln("[bg-94 fg-184] %- 80s "), dateStr)
			currentDay = &event.On
		}

		switch T := event.Payload.(type) {
		default:
			fmt.Printf("unexpected type %T", T)

		case *gogithub.Event:
			payload := event.Payload.(*gogithub.Event)
			fmt.Printf(sgr.MustParseln(eventTemplate), event.On.Format("15:04"), event.Type, payload.Message(""))

		case *gojira.Issue:
			payload := event.Payload.(*gojira.Issue)
			fmt.Printf(sgr.MustParseln(eventTemplate), event.On.Format("15:04"), event.Type, payload.Key+" - "+payload.Fields.Summary)

		case *gojira.ActivityItem:
			payload := event.Payload.(*gojira.ActivityItem)
			fmt.Printf(sgr.MustParseln(eventTemplate), event.On.Format("15:04"), event.Type, re.ReplaceAllString(payload.Title, " "))

		case *gogitlab.Commit:
			payload := event.Payload.(*gogitlab.Commit)
			description := fmt.Sprintf(sgr.MustParse("%s - %s by [bold]%s"), payload.Short_Id, payload.Title, payload.Author_Name)
			fmt.Printf(sgr.MustParseln(eventTemplate), event.On.Format("15:04"), event.Type, description)

		case *gogitlab.FeedCommit:
			payload := event.Payload.(*gogitlab.FeedCommit)
			fmt.Printf(sgr.MustParseln(eventTemplate), event.On.Format("15:04"), event.Type, payload.Title)
		}
	}
}
开发者ID:plouc,项目名称:hound,代码行数:57,代码来源:hound.go

示例3: getSeasonScaler

/*
	get season scaler from time
*/
func (de *DateEncoder) getSeasonScaler(date time.Time) float64 {
	if de.seasonEncoder == nil {
		return 0.0
	}

	//make year 0 based
	dayOfYear := float64(date.YearDay() - 1)
	return dayOfYear

}
开发者ID:Fardinak,项目名称:htm,代码行数:13,代码来源:dateEncoder.go

示例4: same

func same(d date.Date, t time.Time) bool {
	yd, wd := d.ISOWeek()
	yt, wt := t.ISOWeek()
	return d.Year() == t.Year() &&
		d.Month() == t.Month() &&
		d.Day() == t.Day() &&
		d.Weekday() == t.Weekday() &&
		d.YearDay() == t.YearDay() &&
		yd == yt && wd == wt
}
开发者ID:fxtlabs,项目名称:date,代码行数:10,代码来源:date_test.go

示例5: adjustTime

func (trs TimeRangeSchedule) adjustTime(t time.Time) {
	yearDay := t.YearDay()
	if trs.startTime.YearDay() != yearDay {
		trs.startTime = time.Date(t.Year(), t.Month(), t.Day(), trs.startTime.Hour(),
			trs.startTime.Minute(), 0, 0, time.Local)
	}
	if trs.endTime.YearDay() != yearDay {
		trs.endTime = time.Date(t.Year(), t.Month(), t.Day(), trs.endTime.Hour(),
			trs.endTime.Minute(), 0, 0, time.Local)
	}
}
开发者ID:shmiluyu,项目名称:cron,代码行数:11,代码来源:timerange.go

示例6: Strftime

// Strftime formats time according to the directives in the given format string. Any text not listed as a directive will be
// passed through to the output string.
//
// Format meanings:
//
//		[%a]   The abbreviated weekday name (۳ش)
//		[%A]   The full weekday name (یکشنبه)
//		[%b]   The month name (اردیبهشت)
//		[%B]   The month name in pinglish (Ordibehesht)
//		[%d]   Day of the month (01..31)
//		[%e]   Day of the month (1..31)
//		[%j]   Day of the year (1..366)
//		[%m]   Month of the year, zero-padded (01..12)
//		[%_m]  Month of the year, blank-padded ( 1..12)
//		[%-m]  Month of the year, no-padded (1..12)
//		[%w]   Day of the week (Sunday is 0, 0..6)
//		[%x]   Preferred representation for the date alone, no time in format YY/M/D
//		[%y]   Year without a century (00..99)
//		[%Y]   Year with century
//		[%H]   Hour of the day, 24-hour clock (00..23)
//		[%I]   Hour of the day, 12-hour clock (01..12)
//		[%M]   Minute of the hour (00..59)
//		[%p]   Meridian indicator ("بعد از ظهر" or "قبل از ظهر")
//		[%S]   Second of the minute (00..60)
//		[%x]   1392/04/02
//		[%-x]  92/4/2
//		[%X]   Preferred representation for the time alone, no date
//		[%Z]   Time zone name
//		[%%]   Literal %'' character
//
// Example:
// 		jalali.Strftime("Printed on %Y/%m/%d", time.Now())   #=> "Printed on 1392/04/02"
func Strftime(format string, t time.Time) string {
	jyear, jmonth, jday := Gtoj(t)
	output := format
	yy := fmt.Sprintf("%d", jyear)[2:]
	hh := t.Hour()
	if t.Hour() >= 12 {
		hh = t.Hour() - 12
	}
	ampm := persianMeridianIndicatorShort[0]
	if t.Hour() >= 12 {
		ampm = persianMeridianIndicatorShort[1]
	}
	AMPM := persianMeridianIndicator[0]
	if t.Hour() >= 12 {
		AMPM = persianMeridianIndicator[1]
	}

	zone, _ := t.Zone()

	// X:=[("%02d" % @hour),("%02d" % @min),("%02d" % @sec)].join(":"))
	re := [][]string{
		{"%%", "SUBSTITUTION_MARKER"},
		{"%m", fmt.Sprintf("%02d", jmonth)},
		{"%_m", fmt.Sprintf("% 2d", jmonth)},
		{"%-m", fmt.Sprintf("%d", jmonth)},
		{"%a", persianWeekdayNamesShort[t.Weekday()]},
		{"%A", persianWeekdayNames[t.Weekday()]},
		{"%b", persianMonthNames[jmonth]},
		{"%B", persianMonthNamesPEnglish[jmonth]},
		{"%d", fmt.Sprintf("%02d", jday)},
		{"%e", fmt.Sprintf("%d", jday)},
		{"%Y", fmt.Sprintf("%d", jyear)},
		{"%y", yy},
		{"%j", fmt.Sprintf("%d", t.YearDay())},
		{"%H", fmt.Sprintf("%02d", t.Hour())},
		{"%I", fmt.Sprintf("%02d", hh)},
		{"%M", fmt.Sprintf("%02d", t.Minute())},
		{"%S", fmt.Sprintf("%02d", t.Second())},
		{"%p", ampm},
		{"%P", AMPM},
		{"%w", fmt.Sprintf("%d", t.Weekday())},
		{"%Z", zone},
		{"%X", fmt.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second())},
		{"%x", fmt.Sprintf("%d/%02d/%02d", jyear, t.Month(), t.Day())},
		{"%-x", fmt.Sprintf("%s/%d/%d", yy, t.Month(), t.Day())},
		{"SUBSTITUTION_MARKER", "%"},
	}
	for _, r := range re {
		output = strings.Replace(output, r[0], r[1], -1)
	}
	return output
}
开发者ID:shgninc,项目名称:go-jalali,代码行数:84,代码来源:jalali.go

示例7: daysDiff

func daysDiff(a, b time.Time) (days int) {
	cur := b
	for cur.Year() < a.Year() {
		// add 1 to count the last day of the year too.
		days += lastDayOfYear(cur).YearDay() - cur.YearDay() + 1
		cur = firstDayOfNextYear(cur)
	}
	days += a.YearDay() - cur.YearDay()
	if b.AddDate(0, 0, days).After(a) {
		days -= 1
	}
	return days
}
开发者ID:Integralist,项目名称:ufc-event-notifier,代码行数:13,代码来源:ufc.go

示例8: FuzzyTime

func FuzzyTime(t time.Time) string {
	n := time.Now()
	ny, nm, nd := n.Date()
	ty, tm, td := t.Date()
	if ty == ny && tm == nm && td == nd {
		return t.Format("15:04:05")
	}
	if d := n.YearDay() - t.YearDay(); ny == ty && d > -8 && d < 8 {
		return t.Format("02 Jan 06 at 15:04")
	}

	return t.Format("Mon, 02 Jan 06 at 15:04")
}
开发者ID:sarifsystems,项目名称:sarif,代码行数:13,代码来源:format.go

示例9: weekNumber

func weekNumber(t *time.Time, char int) int {
	weekday := int(t.Weekday())

	if char == 'W' {
		// Monday as the first day of the week
		if weekday == 0 {
			weekday = 6
		} else {
			weekday -= 1
		}
	}

	return (t.YearDay() + 6 - weekday) / 7
}
开发者ID:jmptrader,项目名称:timeutil,代码行数:14,代码来源:strftime.go

示例10: TimeMicro

// fromTime converts a time.Time value in a microsecond resolution timestamp.
func TimeMicro(t time.Time) int64 {
	// Ensure the time is in UTC
	t = t.UTC()

	yr := int64(t.Year() - 1)

	// Elapsed taking in to account leap years.
	elapsedDays := int64(yr*365+yr/4-yr/100+yr/400) + int64(t.YearDay()) - 1

	// Remaining seconds.
	elapsedSeconds := (elapsedDays*secondsPerDay + int64(t.Hour())*3600 + int64(t.Minute())*60 + int64(t.Second()))

	return int64(elapsedSeconds*microsPerSecond + int64(t.Nanosecond())/microsPerNano)
}
开发者ID:l-k-,项目名称:origins,代码行数:15,代码来源:time.go

示例11: matches

// matches determines whether the given date is the one referred to by the
// Holiday.
func (h *Holiday) matches(date time.Time) bool {
	if h.Month > 0 {
		if date.Month() != h.Month {
			return false
		}
		if h.Day > 0 {
			return date.Day() == h.Day
		}
		if h.Weekday > 0 && h.Offset != 0 {
			return IsWeekdayN(date, h.Weekday, h.Offset)
		}
	} else if h.Offset > 0 {
		return date.YearDay() == h.Offset
	}
	return false
}
开发者ID:cringlenet,项目名称:cal,代码行数:18,代码来源:holiday.go

示例12: urlPlaceholders

func urlPlaceholders(t time.Time, title string, categories []string) store {
	var (
		year  = t.Year()
		month = t.Month()
		day   = t.Day()
		ph    = store{}
	)
	ph["year"] = fmt.Sprintf("%d", year)
	ph["month"] = fmt.Sprintf("%02d", month)
	ph["i_month"] = fmt.Sprintf("%d", month)
	ph["day"] = fmt.Sprintf("%02d", day)
	ph["i_day"] = fmt.Sprintf("%d", day)
	ph["short_month"] = t.Format("Jan")
	ph["y_day"] = fmt.Sprintf("%d", t.YearDay())
	ph["title"] = title
	ph["categories"] = path.Join(categories...)
	return ph
}
开发者ID:kennylixi,项目名称:dufu,代码行数:18,代码来源:permalinks.go

示例13: numOfDaysBetween

func numOfDaysBetween(from, to time.Time) (count int) {
	years := yearsBetween(from, to)
	if len(years) == 0 {
		return to.YearDay() - from.YearDay()
	}
	for _, v := range years {
		count += daysInYear(v)
	}
	currentYearDays := daysInYear(from.Year()) - from.YearDay()
	count += currentYearDays + to.YearDay()
	return
}
开发者ID:kkfaisal,项目名称:dates,代码行数:12,代码来源:dates.go

示例14: StarDate

// returns decimal year to nearest 52 minutes - usually printed with %9.4f
func StarDate(when time.Time) float64 {
	yr := float64(when.Year())
	dayofyear := float64(when.YearDay())
	//fmt.Printf("%v %v\n", yr, dayofyear)
	var daysinyear float64
	if LeapYear(when) {
		daysinyear = 366
	} else {
		daysinyear = 365
	}
	// note Hour is rounded so should add fraction for Minutes*60+Seconds
	elapsedSeconds := when.Hour() * 3600
	elapsedSeconds += +when.Minute() * 60
	elapsedSeconds += when.Second()
	hrs := (dayofyear-1)*24 + (float64(elapsedSeconds) / 3600.0)
	//fmt.Printf("hrs = %v \n",hrs)
	// TODO should be rounded to .0000
	rv := yr + hrs/(daysinyear*24)
	//rv = math.Round(rv,4 places)
	return rv
}
开发者ID:hotei,项目名称:mdr,代码行数:22,代码来源:mdr_datetime.go

示例15: initTime

func (c *ctx) initTime(config *ctxConfig, t time.Time) {
	if config.date {
		c.year, c.month, c.day = t.Date()
	}
	if config.clock {
		c.hour, c.min, c.sec = t.Clock()
	}
	if config.iso {
		c.isoYear, c.isoWeek = t.ISOWeek()
	}

	if config.millis {
		c.millis = t.Nanosecond() / 1000000
	}

	if config.yearday {
		c.yearday = t.YearDay()
	}

	if config.weekday {
		c.weekday = t.Weekday()
	}
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:23,代码来源:ctx.go


注:本文中的Time.Time.YearDay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。