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


Golang Time.LocalTime函数代码示例

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


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

示例1: main

func main() {
	c := make(chan int)
	go func() {
		time.Sleep(3 * 1e9) //time in nanos. 3 secs
		x := <-c
		fmt.Println("received at", time.LocalTime())
	}()

	fmt.Println("sending at", time.LocalTime())
	c <- 10
	fmt.Println("sent at", time.LocalTime())
}
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:12,代码来源:sync.go

示例2: main

func main() {
	fmt.Print("Go runs on")
	switch os := runtime.GOOS; os {
	case "darwin":
		fmt.Println("OS X.")
	case "linux":
		fmt.Println("Linux.")
	default:
		// freebsd,openbsd,plan9,windows
		fmt.Printf("%s.", os)
	}

	fmt.Println(runtime.GOROOT)

	/**
	Switch cases evaluate cases from top to bottom, stopping when a case succeeds.
	(For example,
	switch i {
		case 0:
		case f():
	}
	does not call f if i==0.)
	**/
	fmt.Println("When`s Saturday?")
	today := time.LocalTime().Weekday
	switch time.Saturday {
	case today + 0:
		fmt.Println("Today.")
	case today + 1:
		fmt.Println("Tomorrow.")
	case today + 2:
		fmt.Println("In tow days.")
	default:
		fmt.Println("Too far away.")
	}

	/**
	Switch without a condition is the same as switch true.
	**/
	t := time.LocalTime()
	switch {
	case t.Hour < 12:
		fmt.Println("Good morning!")
	case t.Hour < 17:
		fmt.Println("Good afternoon.")
	default:
		fmt.Println("Good evening.")
	}
}
开发者ID:freewu,项目名称:learn,代码行数:49,代码来源:switch.go

示例3: Start

func Start(ctx *web.Context, handler *MHandler) *Session {
	session := new(Session)
	session.handler = handler
	session.handler.Clean()
	old := false
	if ctx.Cookies != nil {
		if id, exists := ctx.Cookies["bloody_sess"]; exists {
			session.id = id
			old = true
		}
	}
	if !old {
		// Starts new session
		session.generateId()
		session.handler.Store(session.GetID(), nil)
	}
	rt := session.handler.Retrieve(session.GetID())
	json.Unmarshal(rt.SessionData, &session.Data)
	if session.Data == nil {
		t := make(map[string]interface{})
		session.Data = t
	}
	ctx.SetCookie("bloody_sess", session.GetID(), time.LocalTime().Seconds()+3600)
	return session
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:25,代码来源:session.go

示例4: LogWrite

// This is the FileLogWriter's output method
func (flw *FileLogWriter) LogWrite(rec *LogRecord) (n int, err os.Error) {
	flw.lock.Lock()
	defer flw.lock.Unlock()

	// First, check if we've gone over any of our rotate triggers
	if flw.Good() {
		if (flw.maxlines > 0 && flw.maxlines_curlines >= flw.maxlines) ||
			(flw.maxsize > 0 && flw.maxsize_cursize >= flw.maxsize) ||
			(flw.daily && time.LocalTime().Day != flw.daily_opendate) {
			flw.intRotate()
		}
	}

	// Make sure the writer is (still) good
	if !flw.Good() {
		return -1, os.NewError("File was not opened successfully")
	}

	// Perform the write
	n, err = flw.file.Write([]byte(FormatLogRecord(flw.format, rec)))

	// Update the counts
	if err == nil {
		flw.maxlines_curlines++
		flw.maxsize_cursize += n
	}

	return n, err
}
开发者ID:Kissaki,项目名称:log4go,代码行数:30,代码来源:filelog.go

示例5: addOurReceivedField

func (myRouter *routerStruct) addOurReceivedField(fd *os.File, mailfrom string, rcptto string, helo string, ehlo string, uid string, fn822 string, addReturnPath bool) {

	var wi, fr string = "", ""

	if len(ehlo) != 0 {
		wi = "ESMTP"
		fr = ehlo
	} else {
		wi = "SMTP"
		fr = helo
	}

	dateTime := time.LocalTime().Format("Mon, 02 Jan 2006 15:04:05 -0700")

	if addReturnPath == true {
		r := fmt.Sprintf("Return-Path: <%s>\r\n", mailfrom)
		fd.Write([]byte(r))
	}

	r := fmt.Sprintf("Received: from %s\r\n\tby %s with %s id %s\r\n\tfor %s;\r\n\t%s\r\n",
		fr,
		G_hostname,
		wi,
		uid,
		rcptto,
		dateTime)

	fd.Write([]byte(r))
}
开发者ID:GoogleSourceExpoted,项目名称:goesmtp,代码行数:29,代码来源:router.go

示例6: tch_handleToday

func tch_handleToday(session *BlogSession, items []string) string {
	if len(items) != 1 {
		return "syntax: today\n"
	}

	today_t := time.LocalTime()
	today_t.Hour = 0
	today_t.Minute = 0
	today_t.Second = 0

	today := today_t.Seconds()
	tomorrow := today + (24 * 60 * 60)

	//GetPostsForTimespan(start_timestamp, end_timestamp int64) (posts []BlogPost, err os.Error)

	fmt.Printf("today: %d | tomorro: %d\n", today, tomorrow)

	posts, err := session.Db().GetPostsForTimespan(today, tomorrow, 1)
	if err != nil {
		return err.String() + "\n"
	}

	//post.Comments, _ = session.Db().GetComments(post.Id)
	s := ""
	for _, post := range posts {
		s += session.BlogFormatter().FormatPost(&post, false)
		s += "\n"
	}

	return s
}
开发者ID:moritzpein,项目名称:fettemama,代码行数:31,代码来源:commands.go

示例7: index

func index(ctx *web.Context) string {
	posts := postsForMonth(time.LocalTime()) //Db.GetLastNPosts(10)
	s := RenderHeader()
	s += RenderPosts(&posts)
	s += RenderFooter()
	return s
}
开发者ID:moritzpein,项目名称:fettemama,代码行数:7,代码来源:index.go

示例8: Command

func Command(cmd string) []string {
	command := []byte(strings.ToLower(cmd))
	if what_time.Match(command) {
		current_time := time.LocalTime()
		formatted_time := current_time.Format(time.Kitchen)
		return []string{formatted_time}
	} else if who_are_you.Match(command) {
		return []string{"I am Gopher, I'm here to help."}
	} else if cmd == "gopher quit" {
		os.Exit(0)
	} else if matches := gist.FindSubmatch(command); matches != nil {
		for _, match := range matches {
			fmt.Printf("Match: %s\n", string(match))
		}

		if len(matches) > 1 {
			gist_id, err := strconv.Atoui(string(matches[1]))
			if err != nil {
				fmt.Printf("Could not parse the gist_id: %s\n", string(matches[1]))
				return []string{}
			}
			gist_file := strings.TrimSpace(string(matches[2]))
			fmt.Printf("Gist file: %s\n", gist_file)
			gist_content := GetGist(gist_id, gist_file)
			fmt.Printf("Gist Content: %s\n", gist_content)
			return gist_content
		}
		return []string{}
	} else if matches := hoogle.FindSubmatch([]byte(cmd)); matches != nil {
		return Hoogle(strings.Fields(string(matches[1])))
	} else if matches := man_page.FindSubmatch([]byte(cmd)); matches != nil {
		return Manpage(strings.Fields(string(matches[1])))
	}
	return []string{"Dunno what you are asking me. WTF dude?"}
}
开发者ID:wjlroe,项目名称:gocampfire,代码行数:35,代码来源:commands.go

示例9: Output

func (l *logger) Output(v ...interface{}) {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	actual := time.LocalTime()
	//l.fd.WriteString(fmt.Sprintln(actual.Year, "/", actual.Month, "/", actual.Day, " ", actual.Hour, ":", actual.Minute, ":", actual.Second, " ", v))
	l.fd.WriteString(actual.Format(time.RFC822) + " " + fmt.Sprintln(v...))
}
开发者ID:royger,项目名称:wgo,代码行数:7,代码来源:logger.go

示例10: Create

func (post *PostModel) Create(title string, content string) {
	t := time.LocalTime()
	err := post.c.Insert(&Post{"", title, content, t.Seconds(), 0})
	if err != nil {
		panic(err)
	}
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:7,代码来源:posts.go

示例11: GetFixedUpTime

// Apply offset to local time.
// Returns a Time object: http://golang.org/pkg/time/#Time
func GetFixedUpTime(o HostOffset) time.Time {
	tm := *time.LocalTime()

	switch o.Year.Op {
	case Add:
		tm.Year += int64(o.Year.Value)
	case Subtract:
		tm.Year -= int64(o.Year.Value)
	case Fix:
		tm.Year = int64(o.Year.Value)
	}

	switch o.Month.Op {
	case Add:
		tm.Month += o.Month.Value
	case Subtract:
		tm.Month -= o.Month.Value
	case Fix:
		tm.Month = o.Month.Value
	}

	switch o.Day.Op {
	case Add:
		tm.Day += o.Day.Value
	case Subtract:
		tm.Day -= o.Day.Value
	case Fix:
		tm.Day = o.Day.Value
	}

	switch o.Hour.Op {
	case Add:
		tm.Hour += o.Hour.Value
	case Subtract:
		tm.Hour -= o.Hour.Value
	case Fix:
		tm.Hour = o.Hour.Value
	}

	switch o.Minute.Op {
	case Add:
		tm.Minute += o.Minute.Value
	case Subtract:
		tm.Minute -= o.Minute.Value
	case Fix:
		tm.Minute = o.Minute.Value
	}

	switch o.Second.Op {
	case Add:
		tm.Second += o.Second.Value
	case Subtract:
		tm.Second -= o.Second.Value
	case Fix:
		tm.Second = o.Second.Value
	}

	// fmt.Println(tm.String())
	return tm
}
开发者ID:sysprv,项目名称:time-server,代码行数:62,代码来源:time-server.go

示例12: LogWrite

// This is the XMLLogWriter's output method
func (xlw *XMLLogWriter) LogWrite(rec *LogRecord) (n int, err os.Error) {
	xlw.lock.Lock()
	defer xlw.lock.Unlock()

	// First, check if we've gone over any of our rotate triggers
	if xlw.Good() {
		if (xlw.maxrecords > 0 && xlw.maxrecords_currecords >= xlw.maxrecords) ||
			(xlw.maxsize > 0 && xlw.maxsize_cursize >= xlw.maxsize) ||
			(xlw.daily && time.LocalTime().Day != xlw.daily_opendate) {
			xlw.intRotate()
		}
	}

	// Make sure the writer is (still) good
	if !xlw.Good() {
		return -1, os.NewError("File was not opened successfully")
	}

	// Perform the write
	n, err = xlw.file.Write([]byte(FormatLogRecord("\t<record level=\"%L\">\n\t\t<timestamp>%D %T</timestamp>\n\t\t<source>%S</source>\n\t\t<message>%M</message>\n\t</record>\n", rec)))

	// Update the counts
	if err == nil {
		xlw.maxrecords_currecords++
		xlw.maxsize_cursize += n
	}

	return n, err
}
开发者ID:welterde,项目名称:log4go,代码行数:30,代码来源:xmllog.go

示例13: Execute

// execute a request; date it, sign it, send it
func (bucket *Bucket) Execute(req *http.Request) (resp *http.Response, err os.Error) {
	// time stamp it
	date := time.LocalTime().Format(time.RFC1123)
	req.Header["Date"] = date

	// sign the request
	bucket.Sign(req)

	// open a connection
	conn, err := net.Dial("tcp", "", req.URL.Host+":"+req.URL.Scheme)
	if err != nil {
		return nil, err
	}

	// send the request
	req.Write(conn)

	// now read the response
	reader := bufio.NewReader(conn)
	resp, err = http.ReadResponse(reader, req.Method)
	if err != nil {
		return nil, err
	}

	return
}
开发者ID:sstephens,项目名称:sstephens1,代码行数:27,代码来源:bucket.go

示例14: Log

func (acl *ApacheCombinedLogger) Log(lr *LogRecord) {
	if acl.w == nil {
		return
	}

	host, _, err := net.SplitHostPort(lr.Request.RemoteAddr)
	if err != nil {
		log.Print(fmt.Sprintf("Failed to resolve \"%s\": %s", lr.Request.RemoteAddr, err.String()))
		return
	}

	var b = &bytes.Buffer{}
	fmt.Fprintf(b, "%s - - [%s] ", host, time.LocalTime().Format(apacheTimeFormat))
	fmt.Fprintf(b, "\"%s %s HTTP/%d.%d\" ",
		lr.Request.Method, lr.Request.URL, lr.Request.ProtocolVersion/1000, lr.Request.ProtocolVersion%1000)
	fmt.Fprintf(b, "%d %d \"%s\" \"%s\"\n",
		lr.Status, lr.Written-lr.HeaderSize, lr.Request.Header.Get(web.HeaderReferer),
		lr.Request.Header.Get(web.HeaderUserAgent))

	// Lock to make sure that we don't write while log output is being changed.
	acl.mutex.Lock()
	defer acl.mutex.Unlock()

	acl.w.Write(b.Bytes())
}
开发者ID:rene-dev,项目名称:twister,代码行数:25,代码来源:log.go

示例15: NewFileLogWriter

// NewFileLogWriter creates a new LogWriter which writes to the given file and
// has rotation enabled if rotate is true.
//
// If rotate is true, any time a new log file is opened, the old one is renamed
// with a .### extension to preserve it.  The various Set* methods can be used
// to configure log rotation based on lines, size, and daily.
//
// The standard log-line format is:
//   [%D %T] [%L] (%S) %M
func NewFileLogWriter(fname string, rotate bool) *FileLogWriter {
	w := &FileLogWriter{
		rec:      make(chan *LogRecord, LogBufferLength),
		rot:      make(chan bool),
		filename: fname,
		format:   "[%D %T] [%L] (%S) %M",
		rotate:   rotate,
	}

	// open the file for the first time
	if err := w.intRotate(); err != nil {
		fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.filename, err)
		return nil
	}

	go func() {
		defer func() {
			if w.file != nil {
				fmt.Fprint(w.file, FormatLogRecord(w.trailer, &LogRecord{Created: time.Nanoseconds()}))
				w.file.Close()
			}
		}()

		for {
			select {
			case <-w.rot:
				if err := w.intRotate(); err != nil {
					fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.filename, err)
					return
				}
			case rec, ok := <-w.rec:
				if !ok {
					return
				}
				if (w.maxlines > 0 && w.maxlines_curlines >= w.maxlines) ||
					(w.maxsize > 0 && w.maxsize_cursize >= w.maxsize) ||
					(w.daily && time.LocalTime().Day != w.daily_opendate) {
					if err := w.intRotate(); err != nil {
						fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.filename, err)
						return
					}
				}

				// Perform the write
				n, err := fmt.Fprint(w.file, FormatLogRecord(w.format, rec))
				if err != nil {
					fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.filename, err)
					return
				}

				// Update the counts
				w.maxlines_curlines++
				w.maxsize_cursize += n
			}
		}
	}()

	return w
}
开发者ID:v-gu,项目名称:mysqltc,代码行数:68,代码来源:filelog.go


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