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


Golang Time.In方法代码示例

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


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

示例1: Times

// Times returns the start and stop time for
// the closest Day translation to now.
func (d *Day) Times(now time.Time) (closestStart time.Time, closestStop time.Time) {
	if now.IsZero() {
		Log.Error("Cannot find times without reference")
		return
	}

	if loc, err := d.GetLocation(); loc != nil && err == nil {
		now = now.In(loc)
	}

	// find nearest start time of this slot
	if now.Weekday() == d.Day && todayAt(now, d.Start).Before(now) {
		// if the schedule is for today
		// and we are after that scheduled time,
		// then we have found the closest start
		closestStart = todayAt(now, d.Start)
	} else {
		// Step back a day at a time until we find
		// the most recent day that matches the day
		// of the week of our Day.
		for i := 1; i < 8; i++ {
			sTime := now.Add(-time.Duration(i) * 24 * time.Hour)
			if sTime.Weekday() == d.Day {
				closestStart = todayAt(sTime, d.Start)
				break
			}
		}
	}

	// closestStop is just the closests start plus
	// the duration
	closestStop = closestStart.Add(d.Duration)

	return
}
开发者ID:CyCoreSystems,项目名称:ipc-schedule,代码行数:37,代码来源:day.go

示例2: main

func main() {
	flagutil.Usage = "[seconds]"
	flag.Parse()

	var t time.Time

	// Get our time.
	switch flag.NArg() {
	case 0:
		t = time.Now()
	case 1:
		sec, err := strconv.ParseInt(flag.Arg(0), 10, 64)
		if err != nil {
			log.Fatal(err)
		}
		t = time.Unix(sec, 0)
	default:
		log.Fatal("bad args")
	}

	// Get our timezone.
	if *utc {
		t = t.In(time.UTC)
	}

	// Print the time.
	if *epoch {
		fmt.Println(t.Unix())
	} else {
		fmt.Println(t.Format(time.UnixDate))
	}
}
开发者ID:rkoesters,项目名称:goblin,代码行数:32,代码来源:date.go

示例3: ActiveAt

// ActiveAt says whether the given time is
// wihtin the schedule of this Day schedule.
func (d *Day) ActiveAt(t time.Time) bool {
	if loc, err := d.GetLocation(); loc != nil && err == nil {
		t = t.In(loc)
	}
	start, stop := d.Times(t)
	return t.After(start) && t.Before(stop)
}
开发者ID:CyCoreSystems,项目名称:ipc-schedule,代码行数:9,代码来源:day.go

示例4: differentTZs

func differentTZs(t time.Time) []string {
	var lines []string
	for _, loc := range TZs {
		lines = append(lines, fmt.Sprintf("%s (%s)", t.In(loc).String(), loc.String()))
	}
	return lines
}
开发者ID:Feh,项目名称:guess,代码行数:7,代码来源:guess.go

示例5: FindRecentlyOpened

// FindRecentlyOpened 回傳最近一個開市時間(UTC 0)
func FindRecentlyOpened(date time.Time) time.Time {
	var (
		d     = date.In(utils.TaipeiTimeZone)
		days  = d.Day()
		index int
		tp    *TimePeriod
	)

	for {
		if IsOpen(d.Year(), d.Month(), days) {
			if index == 0 {
				tp = NewTimePeriod(time.Date(d.Year(), d.Month(), days, d.Hour(), d.Minute(), d.Second(), d.Nanosecond(), utils.TaipeiTimeZone))
				if tp.AtBefore() || tp.AtOpen() {
					days--
					for {
						if IsOpen(d.Year(), d.Month(), days) {
							break
						}
						days--
					}
				}
			}
			return time.Date(d.Year(), d.Month(), days, 0, 0, 0, 0, time.UTC)
		}
		days--
		index++
	}

}
开发者ID:668Jerry,项目名称:gogrs,代码行数:30,代码来源:tradingdays.go

示例6: Format

func (*simpleFormatter) Format(level loggo.Level, module string, timestamp time.Time, message string) string {
	ts := timestamp.In(time.UTC).Format("2006-01-02 15:04:05")
	// Just show the last element of the module.
	lastDot := strings.LastIndex(module, ".")
	module = module[lastDot+1:]
	return fmt.Sprintf("%s %s %s %s", ts, level, module, message)
}
开发者ID:kakamessi99,项目名称:juju,代码行数:7,代码来源:main.go

示例7: main

func main() {
	flag.Parse()

	var t time.Time
	var err error
	if timedate == "" {
		t = time.Now()
	} else {
		t, err = time.Parse(time.RFC1123, timedate)
		if err != nil {
			fmt.Println(err)
			return
		}
	}

	zones := strings.Split(timezones, ",")

	fmt.Println(t.Format(time.RFC1123), "(Origin)")
	for _, zone := range zones {
		loc, err := time.LoadLocation(zone)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(t.In(loc).Format(time.RFC1123))
	}
}
开发者ID:siavashs,项目名称:timezones,代码行数:27,代码来源:timezones.go

示例8: Notify

func (notifier *Notify) Notify(name string, url string, lastChecked time.Time, template string, code int, responseTime float64) {
	ssettings := Setting{}
	serversettings, err := ssettings.Get()
	if err != nil {
		log.Println(err)
		return
	}
	settings := Settings{
		Server:   serversettings.Server,
		Email:    serversettings.Email,
		SSL:      serversettings.SSL,
		Username: serversettings.Username,
		Password: serversettings.Password,
		Port:     serversettings.Port,
	}
	layout := "Mon, 01/02/06, 3:04PM MST"
	Local, _ := time.LoadLocation("US/Central")
	localChecked := lastChecked.In(Local).Format(layout)

	var tos []string
	var subject string
	var body string

	if template == "up" {
		tos = []string{notifier.Email}
		subject = name + " Site Restored Notification"
		body = "<html><body><p>Hello " + notifier.Name + "</p><p>The " + name + " website at " + url + " is restored as of " + localChecked + ".</p></body></html>"
	} else {
		tos = []string{notifier.Email}
		subject = name + " Site Outage Warning!"
		body = "<html><body><p>Hello " + notifier.Name + "</p><p>The " + name + " website at " + url + " is down as of " + localChecked + ". It responded with an error code of " + strconv.Itoa(code) + " and a response time of " + strconv.FormatFloat(responseTime, 'g', -1, 64) + " ms.</p></body></html>"
	}
	Send(settings, tos, subject, body, true)
}
开发者ID:janiukjf,项目名称:SiteMonitor,代码行数:34,代码来源:notify.go

示例9: ParseTimestamp

// ParseTimestamp parses the timestamp.
func (ctx EvalContext) ParseTimestamp(s DString) (DTimestamp, error) {
	loc := time.UTC
	if ctx.GetLocation != nil {
		var err error
		if loc, err = ctx.GetLocation(); err != nil {
			return DummyTimestamp, err
		}
	}

	str := string(s)
	var err error

	for _, format := range []string{
		dateFormat,
		TimestampWithOffsetZoneFormat,
		timestampFormat,
		timestampWithNamedZoneFormat,
	} {
		var t time.Time
		if t, err = time.ParseInLocation(format, str, loc); err == nil {
			// Always return the time in the session time zone.
			return DTimestamp{Time: t.In(loc)}, nil
		}
	}

	return DummyTimestamp, err
}
开发者ID:jess-edwards,项目名称:cockroach,代码行数:28,代码来源:eval.go

示例10: ContainsTime

// ContainsTime tests whether a given local time is within the date range. The time range is
// from midnight on the start day to one nanosecond before midnight on the day after the end date.
// Empty date ranges (i.e. zero days) never contain anything.
//
// If a calculation needs to be 'half-open' (i.e. the end date is exclusive), simply use the
// expression 'dateRange.ExtendBy(-1).ContainsTime(t)'
func (dateRange DateRange) ContainsTime(t time.Time) bool {
	if dateRange.days == 0 {
		return false
	}
	utc := t.In(time.UTC)
	return !(utc.Before(dateRange.StartUTC()) || dateRange.EndUTC().Add(minusOneNano).Before(utc))
}
开发者ID:rickb777,项目名称:date,代码行数:13,代码来源:daterange.go

示例11: TZTime

func (engine *Engine) TZTime(t time.Time) time.Time {

	if NULL_TIME != t { // if time is not initialized it's not suitable for Time.In()
		return t.In(engine.TZLocation)
	}
	return t
}
开发者ID:zeuson,项目名称:xorm,代码行数:7,代码来源:engine.go

示例12: TimeZoneFormat

func TimeZoneFormat(t time.Time, tz, format string) string {
	loc, err := time.LoadLocation(tz)
	if err != nil {
		return t.Format(TimeFormat(format))
	}
	return t.In(loc).Format(TimeFormat(format))
}
开发者ID:ego008,项目名称:lessgo,代码行数:7,代码来源:time.go

示例13: 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
}
开发者ID:nvanbenschoten,项目名称:cockroach,代码行数:31,代码来源:types.go

示例14: NewMarkitChartAPIRequest

// Constructor for MarkitChartAPIRequests
func NewMarkitChartAPIRequest(s *Stock, start time.Time, end time.Time) (*MarkitChartAPIRequest, error) {
	loc, err := time.LoadLocation("UTC")
	request := &MarkitChartAPIRequest{
		Stock:     s,
		StartDate: start.In(loc).Format(ISOFormat), // formatted like 2011-06-01T00:00:00-00 in UTC time
		EndDate:   end.In(loc).Format(ISOFormat),
		Url:       markitChartAPIURL,
	}

	// use object to build json parameters for url
	params := MarkitChartAPIRequestParams{
		Normalized: false,
		StartDate:  request.StartDate,
		EndDate:    request.EndDate,
		DataPeriod: "Day",
		Elements: []Element{
			Element{
				Symbol: s.Symbol,
				Type:   "price",
				Params: []string{"ohlc"},
			},
			Element{
				Symbol: s.Symbol,
				Type:   "volume",
			},
		},
	}
	jsonStr, err := json.Marshal(params)
	request.Url = fmt.Sprintf("%s?parameters=%s", request.Url, jsonStr)

	return request, err
}
开发者ID:jhurwich,项目名称:Trendy,代码行数:33,代码来源:markit.go

示例15: BuildTime

func BuildTime(ts time.Time) string {
	loc, _ := time.LoadLocation("America/New_York")
	hour_format := "15"
	hour_s := ts.In(loc).Format(hour_format)
	hour, err := strconv.ParseInt(hour_s, 10, 64)
	if err != nil {
		log.Println(err)
		return ""
	}
	var format string
	if hour > 11 {
		format = ":04 PM, Mon Jan 2"
	} else {
		format = ":04 AM, Mon Jan 2"
	}
	var hour_in12 int
	if hour > 12 { // 1 (PM)
		hour_in12 = int(hour - 12)
	} else if hour > 0 { // 11 (AM)
		hour_in12 = int(hour)
	} else {
		hour_in12 = 12 // midnight
	}
	// final time: {hour_in12}:04 {AM/PM}, Mon Jan 2
	readable_time := strconv.Itoa(hour_in12) + ts.In(loc).Format(format)
	return readable_time
}
开发者ID:agreea,项目名称:corner-kitchen-server,代码行数:27,代码来源:servlet_mealrequest.go


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