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


Golang Time.SecondsToLocalTime函数代码示例

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


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

示例1: Comments

func (b *Bug) Comments() (out []Comment, err os.Error) {
	d, err := os.Open(".entomon/" + string(b.Type) + "/" + b.Id)
	defer d.Close()
	if err != nil {
		return out, nil
	}
	ns, err := d.Readdirnames(-1)
	d.Close()
	if err != nil {
		return
	}
	sort.Strings(ns)
	for _, n := range ns {
		dateauthor := strings.SplitN(n, "--", 2)
		// Now let's put the date into the current timezone...
		date, err := time.Parse(time.RFC3339, dateauthor[0])
		if err == nil {
			dateauthor[0] = time.SecondsToLocalTime(date.Seconds()).Format(
				"January 2, 2006 3:04PM")
		}
		if len(dateauthor) == 2 {
			c := Comment{dateauthor[1], dateauthor[0], ""}
			x, err := ioutil.ReadFile(".entomon/" + b.String() + "/" + n)
			if err != nil {
				return out, err
			}
			c.Text = string(x)
			c = b.stripAttributes(c)
			out = append(out, c)
		}
	}
	return
}
开发者ID:droundy,项目名称:entomonitor,代码行数:33,代码来源:έντομο.go

示例2: getSearchPanelHtml

func (h *SearchPanelHandler) getSearchPanelHtml(hr *http.Request) string {
	fmt.Println("\n=== SearchPanelHandler : Requete reçue ====================")
	fmt.Println(" URL : " + hr.RawURL)
	hr.ParseForm()

	askerId := GetFormValueAsInt(hr, "asker")
	mdpr := GetFormValue(hr, "mdpr") // mot de passe restreint
	tok := GetFormValue(hr, "tok")
	compteOk := false
	var compte *Compte

	db, err := h.store.Connect()
	if err != nil {
		fmt.Printf("Erreur ouverture connexion BD dans makeBestiaryExtractHtml : %s\n", err.String())
		return err.String()
	}
	defer db.Close()

	if askerId > 0 && mdpr != "" {
		compteOk, compte, err = h.store.CheckCompte(db, uint(askerId), mdpr)
	}
	if !compteOk {
		return "Compte non authentifié"
	}
	if tok == "" {
		return "Demande non comprise"
	}
	amis, err := h.store.GetPartageurs(db, askerId)
	if err != nil {
		return fmt.Sprintf("Erreur récupération amis : %s\n", err.String())
	}
	observations, err := h.store.SearchObservations(db, tok, askerId, amis)
	if err != nil {
		return fmt.Sprintf("Erreur recherche : %s\n", err.String())
	}
	if len(observations) == 0 {
		return "Rien trouvé"
	}
	html := fmt.Sprintf("%d résultats :", len(observations))
	html += "<table border='0' cellspacing='1' cellpadding='2' class='mh_tdborder' align='center'>"
	html += "<tr class=mh_tdtitre><td class=mh_tdpage><b>Dist.</b></td><td class=mh_tdpage><b>Réf.</b></td><td class=mh_tdpage><b>Nom</b></td>"
	html += "<td class=mh_tdpage><b>Position</b></td>"
	html += "<td class=mh_tdpage><b>Vu par</b></td><td class=mh_tdpage><b>Le</b></td></tr>"
	for _, o := range observations {
		t := time.SecondsToLocalTime(o.Date)
		var lien string
		if o.Type == "troll" {
			lien = fmt.Sprintf("<a href='javascript:EPV(%d)' class=mh_trolls_1 id=%d>%s</a>", o.Num, o.Num, o.Nom)
		} else if o.Type == "monstre" {
			lien = fmt.Sprintf("<a href='javascript:EMV(%d, 750, 550)' class=mh_monstres id=%d>%s</a>", o.Num, o.Num, o.Nom)
		} else {
			lien = o.Nom
		}
		dist := dist(compte.Troll.X, o.X, compte.Troll.Y, o.Y, compte.Troll.Z, o.Z)
		btnVoir := fmt.Sprintf("<a x=%d y=%d z=%d class=gogo name=zoom>%d  %d  %d</a>", o.X, o.Y, o.Z, o.X, o.Y, o.Z)
		html += fmt.Sprintf("<tr class=mh_tdpage><td>%d</td><td>%d</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td></tr>", dist, o.Num, lien, btnVoir, o.Auteur, t.Format("02/01 à 15h04"))
	}
	html += "</table>"
	return html
}
开发者ID:Chouia,项目名称:Chrall,代码行数:60,代码来源:searchpanelhandler.go

示例3: show

func show(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    q := datastore.NewQuery("Guest").Order("Date")
    count, err := q.Count(c)
    if err != nil {
        http.Error(w, err.String(), http.StatusInternalServerError)
        return
    }

    guests := make([]Guest, 0, count)
    guest_views :=([]Guest_View, count)
    if keys, err := q.GetAll(c, &guests); err != nil {
        http.Error(w, errString(), http.StatusInternalServerError)
        return
    } else {
        for pos, guest := range guests {
            guest_views[pos].Id = keys[pos].IntID()
            guest_views[pos].Name = guest.Name
            localTime := time.SecondsToLocalTime(int64(guest.Date) / 1000000)
            guest_views[pos].Date = fmt.Sprintf("%04d/%02d/%02d %02d:%02d:%02d", localTime.Year, localTime.Month, localTime.Day, localTime.Hour, localTime.Minute, localTime.Second)
        }
    }

    if err := showHTMLTemplate.Execute(w, guest_views); err != nil {
        http.Error(w, err.String(), http.StatusInternalServerError)
    }
}
开发者ID:ghostnotes,项目名称:HelloGo,代码行数:27,代码来源:show.go

示例4: main

func main() {
	ticker := time.NewTicker(1000 * 1000 * 1000)
	for {
		ns := <-ticker.C
		t := time.SecondsToLocalTime(ns / 1000 / 1000 / 1000)
		fmt.Printf("%d-%02d-%02d %02d:%02d:%02d\n", t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second)
	}
}
开发者ID:kawaz,项目名称:go-example,代码行数:8,代码来源:tick1.go

示例5: FormatTime

func FormatTime(nanoSeconds int64, utc bool, format string) string {
	seconds := nanoSeconds / 1000000000
	if utc {
		return time.SecondsToUTC(seconds).Format(format)
	} else {
		return time.SecondsToLocalTime(seconds).Format(format)
	}
	panic("unreachable code")
}
开发者ID:Qyrus,项目名称:graphpaper,代码行数:9,代码来源:time.go

示例6: UnmarshalJSON

func (jt *jTime) UnmarshalJSON(data []byte) os.Error {
	var n int64
	if err := json.Unmarshal(data, &n); err != nil {
		return err
	}
	t := time.SecondsToLocalTime(n)
	*jt = (jTime)(*t)
	return nil
}
开发者ID:hokapoka,项目名称:gostack,代码行数:9,代码来源:jtime.go

示例7: main

func main() {
	os.Setenv("TZ", "GMT")
	flag.Parse()

	arg, _ := strconv.Atoi64(flag.Arg(0))
	t := time.SecondsToLocalTime(arg)
	out := t.Format(time.RFC850)

	os.Stdout.WriteString(out + "\n")
}
开发者ID:andrewrjones,项目名称:epoch2time,代码行数:10,代码来源:epoch2time.go

示例8: getTimeOfDay

func getTimeOfDay(when int64) (tod int, utc_time *time.Time) {
	utc_time = time.SecondsToLocalTime(when)
	tod = 0 // default to morning (midnight to noon)
	switch {
	case utc_time.Hour < 4:
		tod = 3 // night, shift day back 1
	case utc_time.Hour < 12:
		tod = 0 // morning
	case utc_time.Hour < 17:
		tod = 1 // afternoon
	default:
		tod = 2 // evening
	}
	if tod == 3 {
		// Quick hack to mark night time as part of the previous day
		utc_time = time.SecondsToLocalTime(when - 86400)
	}
	return
}
开发者ID:toddcblank,项目名称:gobook,代码行数:19,代码来源:db.go

示例9: index

// renders /
func index(ctx *web.Context) string {
	css, ok := ctx.Params["css"]
	if ok {
		SetCSS(ctx, css)
		ctx.Redirect(302, "/")
		return "ok"
	}
	//posts := postsForMonth(time.LocalTime()) //Db.GetLastNPosts(10)

	//	posts := lastPosts(0xff)
	posts := postsForLastNDays(4)
	if len(posts) <= 0 {
		posts = lastPosts(23)
	}
	//fmt.Printf("posts: %#v\n", posts)
	//embedded struct - our mustache templates need a NumOfComments field to render
	//but we don't want to put that field into the BlogPost Struct so it won't get stored
	//into the DB
	type MyPost struct {
		BlogPost
		NumOfComments int
	}

	//posts ordered by date. this is ugly. TODO: look up if mustache hase something to handle this situation
	type Date struct {
		Date  string
		Posts []MyPost
	}
	Db := DBGet()
	defer Db.Close()

	//loop through our posts and put them into the appropriate date structure
	dates := []Date{}
	var cur_date time.Time
	var date *Date
	for _, p := range posts {
		post_date := time.SecondsToLocalTime(p.Timestamp)
		if !(cur_date.Day == post_date.Day && cur_date.Month == post_date.Month && cur_date.Year == post_date.Year) {
			cur_date = *post_date
			dates = append(dates, Date{Date: cur_date.Format("Mon Jan _2 2006")})
			date = &dates[len(dates)-1]
		}
		p.Comments, _ = Db.GetComments(p.Id)
		mp := MyPost{p, len(p.Comments)}
		date.Posts = append(date.Posts, mp)
	}
	m := map[string]interface{}{
		"Dates": dates,
	}

	tmpl, _ := mustache.ParseFile("templ/index.mustache")
	s := tmpl.Render(&m, getCSS(ctx))
	return s
}
开发者ID:kybernetyk,项目名称:fettemama,代码行数:55,代码来源:index.go

示例10: GetLastModif

func GetLastModif(file *os.File) (rv string, err os.Error) {
	rv = ""
	st, err := file.Stat()
	if err != nil {
		return rv, err
	}

	t := time.SecondsToLocalTime(st.Mtime_ns / 1e9)
	rv = t.Format(time.RFC1123)
	return rv, err
}
开发者ID:anvie,项目名称:Anscdn,代码行数:11,代码来源:filemon.go

示例11: String

func String(thisTask TaskId) string {
	var ret string
	info := taskMap[thisTask]
	if info.EndTime == 0 {
		return ""
	}
	timeSpent := info.EndTime - info.StartTime
	niceTimeSpent := float64(timeSpent) / float64(1000000000)
	timeStamp := time.SecondsToLocalTime(time.Seconds())
	ret = "\n" + timeStamp.String() + ": " + info.TaskName + ": " + fmt.Sprintf("%f", niceTimeSpent) + " seconds\n"
	return ret
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:12,代码来源:logger.go

示例12: Value

func (de *DateEdit) Value() *time.Time {
	st, err := de.systemTime()
	if err != nil {
		return nil
	}

	if st == nil {
		return nil
	}

	return time.SecondsToLocalTime(systemTimeToTime(st).Seconds())
}
开发者ID:wiloe,项目名称:walk,代码行数:12,代码来源:dateedit.go

示例13: ServeHTTP

func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if redirect(w, r) {
		return
	}

	relpath := r.URL.Path[len(h.pattern):]
	abspath := absolutePath(relpath, h.fsRoot)
	var mode PageInfoMode
	if relpath != builtinPkgPath {
		mode = exportsOnly
	}
	if r.FormValue("m") != "src" {
		mode |= genDoc
	}
	info := h.getPageInfo(abspath, relpath, r.FormValue("p"), mode)
	if info.Err != nil {
		log.Print(info.Err)
		serveError(w, r, relpath, info.Err)
		return
	}

	if r.FormValue("f") == "text" {
		contents := applyTemplate(packageText, "packageText", info)
		serveText(w, contents)
		return
	}

	var title, subtitle string
	switch {
	case info.PAst != nil:
		title = "Package " + info.PAst.Name.Name
	case info.PDoc != nil:
		switch {
		case info.IsPkg:
			title = "Package " + info.PDoc.PackageName
		case info.PDoc.PackageName == fakePkgName:
			// assume that the directory name is the command name
			_, pkgname := path.Split(path.Clean(relpath))
			title = "Command " + pkgname
		default:
			title = "Command " + info.PDoc.PackageName
		}
	default:
		title = "Directory " + relativeURL(info.Dirname)
		if *showTimestamps {
			subtitle = "Last update: " + time.SecondsToLocalTime(info.DirTime).String()
		}
	}

	contents := applyTemplate(packageHTML, "packageHTML", info)
	servePage(w, title, subtitle, "", contents)
}
开发者ID:WXB506,项目名称:golang,代码行数:52,代码来源:godoc.go

示例14: GwtDate

func GwtDate(reg *Registry, strtable, payload []string, partype string, idxv int) (interface{}, int, os.Error) {
	vb64 := payload[idxv+1]
	datab, err := ToLong(vb64)
	if err != nil {
		return nil, 2, err
	}

	//milli := datab % 1000 (maybe when GAE supports Nanoseconds)
	datab = datab / 1000
	t := time.SecondsToLocalTime(datab)

	return t, 2, nil
}
开发者ID:hpcorona,项目名称:gowt,代码行数:13,代码来源:types.go

示例15: TestRoundDown

func TestRoundDown(t *testing.T) {
	tf := "2006-01-02 15:04:05 MST"
	samples := []struct {
		date, expected string
		delta          TimeDelta
	}{
		// Simple cases
		{"2011-07-04 16:43:23 CEST", "2011-07-04 16:43:00 CEST", Minute{1}},
		{"2011-07-04 16:43:23 CEST", "2011-07-04 16:40:00 CEST", Minute{5}},
		{"2011-07-04 16:43:23 CEST", "2011-07-04 16:40:00 CEST", Minute{10}},
		{"2011-07-04 16:43:23 CEST", "2011-07-04 16:30:00 CEST", Minute{15}},
		{"2011-07-04 16:43:23 CEST", "2011-07-04 16:00:00 CEST", Hour{1}},
		{"2011-07-04 16:43:23 CEST", "2011-07-04 12:00:00 CEST", Hour{6}},

		// Around daylight saving switch
		{"2011-03-27 04:15:16 CEST", "2011-03-27 04:00:00 CEST", Hour{1}},
		{"2011-03-27 04:15:16 CEST", "2011-03-27 00:00:00 CET", Hour{5}},

		{"2011-07-04 16:43:23 CEST", "2011-01-01 00:00:00 CET", Year{1}},
		{"2011-07-04 16:43:23 CEST", "2010-01-01 00:00:00 CET", Year{10}},
	}

	for _, sample := range samples {
		date, e1 := time.Parse(tf, sample.date)
		expected, e2 := time.Parse(tf, sample.expected)
		if e1 != nil || e2 != nil {
			t.FailNow()
		}
		date = time.SecondsToLocalTime(date.Seconds())
		expected = time.SecondsToLocalTime(expected.Seconds())
		sample.delta.RoundDown(date)
		if date.Seconds() != expected.Seconds() {
			t.Errorf("RoundDown %s to %s != %s, was %s", sample.date, sample.delta,
				sample.expected, date.Format(tf))
		}
	}

}
开发者ID:sankark,项目名称:golang-stuff,代码行数:38,代码来源:time_test.go


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