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


Golang Time.Local方法代码示例

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


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

示例1: GetTasks

//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status string) types.Context {
	var task []types.Task
	var context types.Context
	var TaskID int
	var TaskTitle string
	var TaskContent string
	var TaskCreated time.Time
	var getTasksql string

	if status == "pending" {
		getTasksql = "select id, title, content, created_date from task where finish_date is null and is_deleted='N' order by created_date asc"
	} else if status == "deleted" {
		getTasksql = "select id, title, content, created_date from task where is_deleted='Y' order by created_date asc"
	} else if status == "completed" {
		getTasksql = "select id, title, content, created_date from task where finish_date is not null order by created_date asc"
	}

	rows, err := database.Query(getTasksql)
	if err != nil {
		fmt.Println(err)
	}
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
		TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			fmt.Println(err)
		}
		TaskCreated = TaskCreated.Local()
		a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
		task = append(task, a)
	}
	context = types.Context{Tasks: task, Navigation: status}
	return context
}
开发者ID:benkasminbullock,项目名称:Tasks,代码行数:37,代码来源:db.go

示例2: GetTasks

//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status string) (types.Context, error) {
	var task []types.Task
	var context types.Context
	var TaskID int
	var TaskTitle string
	var TaskContent string
	var TaskCreated time.Time
	var TaskPriority string
	var getTasksql string

	basicSQL := "select id, title, content, created_date, priority from task "
	if status == "pending" {
		getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
	} else if status == "deleted" {
		getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc"
	} else if status == "completed" {
		getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc"
	}

	rows := database.query(getTasksql)
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority)
		TaskContent = string(md.Markdown([]byte(TaskContent)))
		// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			log.Println(err)
		}
		TaskCreated = TaskCreated.Local()
		a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20], Priority: TaskPriority}
		task = append(task, a)
	}
	context = types.Context{Tasks: task, Navigation: status}
	return context, nil
}
开发者ID:dot-Sean,项目名称:Tasks,代码行数:37,代码来源:tasks.go

示例3: fillScope

// fillScope - given a scope and reference variables, we fill the exact variables from the now, fields and tags.
func fillScope(vars *stateful.Scope, referenceVariables []string, now time.Time, fields models.Fields, tags models.Tags) error {
	for _, refVariableName := range referenceVariables {
		if refVariableName == "time" {
			vars.Set("time", now.Local())
			continue
		}

		// Support the error with tags/fields collision
		var fieldValue interface{}
		var isFieldExists bool
		var tagValue interface{}
		var isTagExists bool

		if fieldValue, isFieldExists = fields[refVariableName]; isFieldExists {
			vars.Set(refVariableName, fieldValue)
		}

		if tagValue, isTagExists = tags[refVariableName]; isTagExists {
			if isFieldExists {
				return fmt.Errorf("cannot have field and tags with same name %q", refVariableName)
			}
			vars.Set(refVariableName, tagValue)
		}
		if !isFieldExists && !isTagExists {
			if !vars.Has(refVariableName) {
				return fmt.Errorf("no field or tag exists for %s", refVariableName)
			}
		}
	}

	return nil
}
开发者ID:wutaizeng,项目名称:kapacitor,代码行数:33,代码来源:expr.go

示例4: GetTasks

func GetTasks(status string) []types.Task {
	var task []types.Task
	var TaskId int
	var TaskTitle string
	var TaskContent string
	var TaskCreated time.Time
	var getTasksql string
	if status == "pending" {
		getTasksql = "select id, title, content, created_date from task where finish_date is null and is_deleted='N' order by created_date asc"
	} else if status == "trashed" {
		getTasksql = "select id, title, content, created_date from task where is_deleted='Y' order by created_date asc"
	} else if status == "complete" {
		getTasksql = "select id, title, content, created_date from task where finish_date is not null order by created_date asc"
	}

	rows, err := database.Query(getTasksql)
	if err != nil {
		fmt.Println(err)
	}
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&TaskId, &TaskTitle, &TaskContent, &TaskCreated)
		if err != nil {
			fmt.Println(err)
		}
		TaskCreated = TaskCreated.Local()
		a := types.Task{Id: TaskId, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
		task = append(task, a)
	}

	return task
}
开发者ID:puma007,项目名称:Tasks,代码行数:32,代码来源:db.go

示例5: GetComments

//GetComments is used to get comments, all of them.
//We do not want 100 different pages to show tasks, we want to use as few pages as possible
//so we are going to populate everything on the damn home pages
func GetComments(username string) (map[int][]types.Comment, error) {
	commentMap := make(map[int][]types.Comment)

	var taskID int
	var comment types.Comment
	var created time.Time

	userID, err := GetUserID(username)
	if err != nil {
		return commentMap, err
	}
	stmt := "select c.id, c.taskID, c.content, c.created, u.username from comments c, task t, user u where t.id=c.taskID and c.user_id=t.user_id and t.user_id=u.id and u.id=?"
	rows := database.query(stmt, userID)

	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created, &comment.Username)
		comment.Content = string(md.Markdown([]byte(comment.Content)))
		if err != nil {
			return commentMap, err
		}
		// comment.Content = string(md.Markdown([]byte(comment.Content))) ## have to fix the <p> issue markdown support
		created = created.Local()
		comment.Created = created.Format("Jan 2 2006 15:04:05")
		commentMap[taskID] = append(commentMap[taskID], comment)
	}
	return commentMap, nil
}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:31,代码来源:tasks.go

示例6: populateTimeCells

func populateTimeCells(startTime time.Time, endTime time.Time) (ui.TableCell, ui.TableCell, ui.TableCell) {
	var startTimeCell ui.TableCell
	var endTimeCell ui.TableCell
	var durationCell ui.TableCell

	startTime = startTime.Local()
	endTime = endTime.Local()
	zeroTime := time.Unix(0, 0)

	if startTime == zeroTime {
		startTimeCell.Contents = "n/a"
	} else {
		startTimeCell.Contents = startTime.Format(timeDateLayout)
	}

	if endTime == zeroTime {
		endTimeCell.Contents = "n/a"
		durationCell.Contents = fmt.Sprintf("%v+", roundSecondsOffDuration(time.Since(startTime)))
	} else {
		endTimeCell.Contents = endTime.Format(timeDateLayout)
		durationCell.Contents = endTime.Sub(startTime).String()
	}

	if startTime == zeroTime && endTime == zeroTime {
		durationCell.Contents = "n/a"
	}

	return startTimeCell, endTimeCell, durationCell
}
开发者ID:ArthurHlt,项目名称:fly,代码行数:29,代码来源:builds.go

示例7: Queries

func (b *QueryNode) Queries(start, stop time.Time) ([]*Query, error) {
	now := time.Now()
	if stop.IsZero() {
		stop = now
	}
	// Crons are sensitive to timezones.
	// Make sure we are using local time.
	current := start.Local()
	queries := make([]*Query, 0)
	for {
		current = b.ticker.Next(current)
		if current.IsZero() || current.After(stop) {
			break
		}
		qstop := current.Add(-1 * b.b.Offset)
		if qstop.After(now) {
			break
		}

		q, err := b.query.Clone()
		if err != nil {
			return nil, err
		}
		q.SetStartTime(qstop.Add(-1 * b.b.Period))
		q.SetStopTime(qstop)
		queries = append(queries, q)
	}
	return queries, nil
}
开发者ID:influxdata,项目名称:kapacitor,代码行数:29,代码来源:batch.go

示例8: FormatDate

// FormatDate converts a time.Time value to a formatted displayable datetime
func (viewHelper *ViewHelper) FormatDate(value time.Time) string {
	viewTime := value.Local().Format("2006-01-02 15:04:05")
	if viewTime == "0000-12-31 20:00:00" {
		return ""
	}

	return viewTime
}
开发者ID:swizzley,项目名称:go-common,代码行数:9,代码来源:view_helper.go

示例9: logInfo

func logInfo(trid int, sTime time.Time, msg string, params ...interface{}) {
	//timestamp spentTime peer x-real-ip method status 'request URI' message
	spew.Fprintf(os.Stderr, "Thread %d: %s %d %s\n",
		trid,
		sTime.Local().Format("2006-01-02-15-04-05.000"),
		int(time.Now().Sub(sTime).Seconds()*1000),
		spew.Sprintf(msg, params...),
	)
}
开发者ID:gitinsky,项目名称:aspk-get-stat,代码行数:9,代码来源:log.go

示例10: computeRolloverTime

// Work out the rollover time based on the specified time.
func (self *TimedRotatingFileHandler) computeRolloverTime(
	currentTime time.Time) time.Time {

	result := currentTime.Add(self.interval)
	// If we are rolling over at midnight or weekly, then the interval is
	// already known.  What we need to figure out is WHEN the next interval is.
	// In other words, if you are rolling over at midnight, then
	// your base interval is 1 day, but you want to start that one day clock
	// at midnight, not now.
	// So, we have to fudge the rolloverTime value in order trigger the first
	// rollover at the right time.  After that, the regular interval will
	// take care of the rest.
	// Note that this code doesn't care about leap seconds.
	if (self.when == "MIDNIGHT") || strings.HasPrefix(self.when, "W") {
		var t time.Time
		if self.utc {
			t = currentTime.UTC()
		} else {
			t = currentTime.Local()
		}
		dayStartTime := time.Date(
			t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
		result = currentTime.Add(Day - t.Sub(dayStartTime))
		// If we are rolling over on a certain day, add in the number of days
		// until the next rollover, but offset by 1 since we just calculated
		// the time until the next day starts.  There are three cases:
		// Case 1) The day to rollover is today; in this case, do nothing
		// Case 2) The day to rollover is further in the interval (i.e.,
		//         today is day 3 (Wednesday) and rollover is on day 6
		//         (Saturday). Days to next rollover is simply 6 - 3, or 3)
		// Case 3) The day to rollover is behind us in the interval (i.e.,
		//         today is day 5 (Friday) and rollover is on day 4 (Thursday).
		//         Days to rollover is 6 - 5 + 4 + 1, or 6.)  In this case,
		//         it's the number of days left in the current week (1) plus
		//         the number of days in the next week until the
		//         rollover day (5).
		// THe calculations described in 2) and 3) above need to
		// have a day added.  This is because the above time calculation
		// takes us to midnight on this day, i.e., the start of the next day.
		if strings.HasPrefix(self.when, "W") {
			weekday := int(t.Weekday())
			if weekday != self.weekday {
				var daysToWait int
				if weekday < self.weekday {
					daysToWait = self.weekday - weekday
				} else {
					daysToWait = 6 - weekday + self.weekday + 1
				}
				result = result.Add(time.Duration(int64(daysToWait) * int64(Day)))
				// NOTE: we skip the daylight savings time issues here
				// because time library in Golang doesn't support it.
			}
		}
	}
	return result
}
开发者ID:zzn01,项目名称:go-logging-1,代码行数:57,代码来源:handler_timed_rotating_file.go

示例11: AppendTime

func AppendTime(b []byte, tm time.Time, quote bool) []byte {
	if quote {
		b = append(b, '\'')
	}
	b = append(b, tm.Local().Format(timestamptzFormat)...)
	if quote {
		b = append(b, '\'')
	}
	return b
}
开发者ID:housinganywhere,项目名称:pg,代码行数:10,代码来源:time.go

示例12: FormatTime

// FormatTime returns a string with the local time formatted
// in an arbitrary format used for status or and localized tz
// or in UTC timezone and format RFC3339 if u is specified.
func FormatTime(t *time.Time, formatISO bool) string {
	if formatISO {
		// If requested, use ISO time format.
		// The format we use is RFC3339 without the "T". From the spec:
		// NOTE: ISO 8601 defines date and time separated by "T".
		// Applications using this syntax may choose, for the sake of
		// readability, to specify a full-date and full-time separated by
		// (say) a space character.
		return t.UTC().Format("2006-01-02 15:04:05Z")
	}
	// Otherwise use local time.
	return t.Local().Format("02 Jan 2006 15:04:05Z07:00")
}
开发者ID:imoapps,项目名称:juju,代码行数:16,代码来源:format.go

示例13: GetTasks

//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status, category string) (types.Context, error) {
	var tasks []types.Task
	var task types.Task
	var TaskCreated time.Time
	var context types.Context
	var getTasksql string
	var rows *sql.Rows

	comments := GetComments()

	basicSQL := "select id, title, content, created_date, priority from task t"
	if status == "pending" && category == "" {
		getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
	} else if status == "deleted" {
		getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc"
	} else if status == "completed" {
		getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc"
	}

	if category != "" {
		status = category
		getTasksql = "select t.id, title, content, created_date, priority from task t, category c where c.id = t.cat_id and name = ?  and  t.is_deleted!='Y' and t.finish_date is null  order by priority desc, created_date asc, finish_date asc"
		rows, err = database.db.Query(getTasksql, category)
		if err != nil {
			log.Println("something went wrong while getting query")
		}
	} else {
		rows = database.query(getTasksql)
	}
	defer rows.Close()
	for rows.Next() {
		task = types.Task{}
		err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority)
		task.Content = string(md.Markdown([]byte(task.Content)))
		// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			log.Println(err)
		}

		if comments[task.Id] != nil {
			task.Comments = comments[task.Id]
		}

		TaskCreated = TaskCreated.Local()
		task.Created = TaskCreated.Format(time.UnixDate)[0:20]

		tasks = append(tasks, task)
	}
	context = types.Context{Tasks: tasks, Navigation: status}
	return context, nil
}
开发者ID:devshell,项目名称:Tasks,代码行数:53,代码来源:tasks.go

示例14: mergeFieldsAndTags

func mergeFieldsAndTags(now time.Time, fields models.Fields, tags models.Tags) (*tick.Scope, error) {
	scope := tick.NewScope()
	scope.Set("time", now.Local())
	for k, v := range fields {
		if _, ok := tags[k]; ok {
			return nil, fmt.Errorf("cannot have field and tags with same name %q", k)
		}
		scope.Set(k, v)
	}
	for k, v := range tags {
		scope.Set(k, v)
	}
	return scope, nil
}
开发者ID:aglagla,项目名称:kapacitor,代码行数:14,代码来源:expr.go

示例15: SearchTask

//SearchTask is used to return the search results depending on the query
func SearchTask(username, query string) (types.Context, error) {
	var tasks []types.Task
	var task types.Task
	var TaskCreated time.Time
	var context types.Context

	comments, err := GetComments(username)
	if err != nil {
		log.Println("SearchTask: something went wrong in finding comments")
	}

	userID, err := GetUserID(username)
	if err != nil {
		return context, err
	}

	stmt := "select t.id, title, content, created_date, priority, c.name from task t, category c where t.user_id=? and c.id = t.cat_id and (title like '%" + query + "%' or content like '%" + query + "%') order by created_date desc"

	rows := database.query(stmt, userID, query, query)
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category)
		if err != nil {
			log.Println(err)
		}

		if comments[task.Id] != nil {
			task.Comments = comments[task.Id]
		}

		task.Title = strings.Replace(task.Title, query, "<span class='highlight'>"+query+"</span>", -1)
		task.Content = strings.Replace(task.Content, query, "<span class='highlight'>"+query+"</span>", -1)
		task.Content = string(md.Markdown([]byte(task.Content)))

		TaskCreated = TaskCreated.Local()
		CurrentTime := time.Now().Local()
		week := TaskCreated.AddDate(0, 0, 7)

		if (week.String() < CurrentTime.String()) && (task.Priority != "1") {
			task.IsOverdue = true // If one week then overdue by default
		}
		task.Created = TaskCreated.Format("Jan 2 2006")

		tasks = append(tasks, task)
	}
	context = types.Context{Tasks: tasks, Search: query, Navigation: "search"}
	return context, nil
}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:49,代码来源:tasks.go


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