本文整理汇总了Golang中github.com/astaxie/beego.Date函数的典型用法代码示例。如果您正苦于以下问题:Golang Date函数的具体用法?Golang Date怎么用?Golang Date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Date函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateTimeLimitCode
// create a time limit code
// code format: 12 length date time string + 6 minutes string + 40 sha1 encoded string
func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string {
format := "YmdHi"
var start, end time.Time
var startStr, endStr string
if startInf == nil {
// Use now time create code
start = time.Now()
startStr = beego.Date(start, format)
} else {
// use start string create code
startStr = startInf.(string)
start, _ = beego.DateParse(startStr, format)
startStr = beego.Date(start, format)
}
end = start.Add(time.Minute * time.Duration(minutes))
endStr = beego.Date(end, format)
// create sha1 encode string
sh := sha1.New()
sh.Write([]byte(data + setting.SecretKey + startStr + endStr + ToStr(minutes)))
encoded := hex.EncodeToString(sh.Sum(nil))
code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
return code
}
开发者ID:wildex,项目名称:wetalk,代码行数:30,代码来源:tools.go
示例2: InsertOrUpdate
//insert or update point
func (m *Point) InsertOrUpdate() error {
o := orm.NewOrm()
q := Point{Id: m.Id}
err := o.Read(&q)
if nil != err { // not exit, insert
m.CreateTime = beego.Date(time.Now(), "Y-m-d H:i:s")
m.Status = 10
if _, err := o.Insert(m); err != nil {
return err
}
} else { // update
_, err := o.QueryTable(new(Point)).Filter("Id", m.Id).Update(orm.Params{
"Id": m.Id,
"Name": m.Name,
"Type": m.Type,
"Hours": m.Hours,
"Stars": m.Stars,
"Points": m.Points,
//"StartTime": m.StartTime,
//"EndTime": m.EndTime,
"UpdateTime": beego.Date(time.Now(), "Y-m-d H:i:s"),
})
if nil != err {
return err
}
}
return nil
}
开发者ID:zengcheng,项目名称:sfs,代码行数:31,代码来源:point.go
示例3: GetWeekPoints
//get specify week points.
//@ w param specify how many weeks data to get (not include this week)
func (this *Point) GetWeekPoints(w int) ([]string, interface{}) {
var points []orm.Params
o := orm.NewOrm()
index_keys := []string{}
result := make(map[string]interface{})
t := time.Now()
sunday_str := this.GetSunday(t)
t, _ = beego.DateParse(sunday_str, "Y-m-d")
for i := w; i >= 0; i-- {
last_sunday := t.AddDate(0, 0, -7*i)
last_monday := last_sunday.AddDate(0, 0, -6)
last_sunday = last_sunday.Add(time.Hour*time.Duration(23) + time.Minute*time.Duration(59) + time.Second*time.Duration(59))
end_time := beego.Date(last_sunday, "Y-m-d H:i:s")
end_date := beego.Date(last_sunday, "Y-m-d")
start_time := beego.Date(last_monday, "Y-m-d")
data := make(map[string]interface{})
data["start_time"] = start_time
data["end_date"] = end_date
data["end_time"] = end_time
data["time_str"] = start_time + "_" + end_time
o.QueryTable(new(Point)).Filter("start_time__gte", start_time).Filter("end_time__lte", end_time).Filter("status", 10).Values(&points)
data["point"] = points
result[end_time] = data
// index_keys[w-i] = end_time
index_keys = append(index_keys, end_time)
}
return index_keys, result
}
开发者ID:zengcheng,项目名称:sfs,代码行数:35,代码来源:point.go
示例4: List
// 任务列表
func (this *TaskController) List() {
page, _ := this.GetInt("page")
if page < 1 {
page = 1
}
groupId, _ := this.GetInt("groupid")
filters := make([]interface{}, 0)
if groupId > 0 {
filters = append(filters, "group_id", groupId)
}
result, count := models.TaskGetList(page, this.pageSize, filters...)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["name"] = v.TaskName
row["cron_spec"] = v.CronSpec
row["status"] = v.Status
row["description"] = v.Description
e := jobs.GetEntryById(v.Id)
if e != nil {
row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s")
row["prev_time"] = "-"
if e.Prev.Unix() > 0 {
row["prev_time"] = beego.Date(e.Prev, "Y-m-d H:i:s")
} else if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
}
row["running"] = 1
} else {
row["next_time"] = "-"
if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
} else {
row["prev_time"] = "-"
}
row["running"] = 0
}
list[k] = row
}
// 分组列表
groups, _ := models.TaskGroupGetList(1, 100)
this.Data["pageTitle"] = "任务列表"
this.Data["list"] = list
this.Data["groups"] = groups
this.Data["groupid"] = groupId
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("TaskController.List", "groupid", groupId), true).ToString()
this.display()
}
开发者ID:avldya,项目名称:webcron,代码行数:54,代码来源:task.go
示例5: Post
func (this *LoginController) Post() {
this.TplNames = "login.tpl"
this.Ctx.Request.ParseForm()
username := this.Ctx.Request.Form.Get("username")
password := this.Ctx.Request.Form.Get("password")
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
now := beego.Date(time.Now(), "Y-m-d H:i:s")
userInfo := models.GetUserInfo(username)
if userInfo.Password == newPass {
var users models.User
users.Last_logintime = now
models.UpdateUserInfo(users)
//登录成功设置session
sess := this.StartSession()
sess.Set("uid", userInfo.Id)
sess.Set("uname", userInfo.Username)
this.Ctx.Redirect(302, "/")
}
this.Ctx.Redirect(302, "/")
}
开发者ID:huwenshu,项目名称:blogs,代码行数:29,代码来源:login.go
示例6: Logs
// 任务执行日志列表
func (this *TaskController) Logs() {
taskId, _ := this.GetInt("id")
page, _ := this.GetInt("page")
if page < 1 {
page = 1
}
task, err := models.TaskGetById(taskId)
if err != nil {
this.showMsg(err.Error())
}
result, count := models.TaskLogGetList(page, this.pageSize, "task_id", task.Id)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["start_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
row["process_time"] = float64(v.ProcessTime) / 1000
row["ouput_size"] = libs.SizeFormat(float64(len(v.Output)))
row["status"] = v.Status
list[k] = row
}
this.Data["pageTitle"] = "任务执行日志"
this.Data["list"] = list
this.Data["task"] = task
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("TaskController.Logs", "id", taskId), true).ToString()
this.display()
}
开发者ID:avldya,项目名称:webcron,代码行数:32,代码来源:task.go
示例7: ViewLog
// 查看日志详情
func (this *TaskController) ViewLog() {
id, _ := this.GetInt("id")
taskLog, err := models.TaskLogGetById(id)
if err != nil {
this.showMsg(err.Error())
}
task, err := models.TaskGetById(taskLog.TaskId)
if err != nil {
this.showMsg(err.Error())
}
data := make(map[string]interface{})
data["id"] = taskLog.Id
data["output"] = taskLog.Output
data["error"] = taskLog.Error
data["start_time"] = beego.Date(time.Unix(taskLog.CreateTime, 0), "Y-m-d H:i:s")
data["process_time"] = float64(taskLog.ProcessTime) / 1000
data["ouput_size"] = libs.SizeFormat(float64(len(taskLog.Output)))
data["status"] = taskLog.Status
this.Data["task"] = task
this.Data["data"] = data
this.Data["pageTitle"] = "查看日志"
this.display()
}
开发者ID:avldya,项目名称:webcron,代码行数:28,代码来源:task.go
示例8: Index
// 首页
func (this *MainController) Index() {
this.Data["pageTitle"] = "系统概况"
// 即将执行的任务
entries := jobs.GetEntries(30)
jobList := make([]map[string]interface{}, len(entries))
for k, v := range entries {
row := make(map[string]interface{})
job := v.Job.(*jobs.Job)
row["task_id"] = job.GetId()
row["task_name"] = job.GetName()
row["next_time"] = beego.Date(v.Next, "Y-m-d H:i:s")
jobList[k] = row
}
// 最近执行的日志
logs, _ := models.TaskLogGetList(1, 20)
recentLogs := make([]map[string]interface{}, len(logs))
for k, v := range logs {
task, err := models.TaskGetById(v.TaskId)
taskName := ""
if err == nil {
taskName = task.TaskName
}
row := make(map[string]interface{})
row["task_name"] = taskName
row["id"] = v.Id
row["start_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
row["process_time"] = float64(v.ProcessTime) / 1000
row["ouput_size"] = libs.SizeFormat(float64(len(v.Output)))
row["output"] = beego.Substr(v.Output, 0, 100)
row["status"] = v.Status
recentLogs[k] = row
}
this.Data["recentLogs"] = recentLogs
this.Data["jobs"] = jobList
this.Data["cpuNum"] = runtime.NumCPU()
this.display()
}
开发者ID:huncent,项目名称:webcron,代码行数:41,代码来源:main.go
示例9: Prepare
// Prepare implemented Prepare method for baseRouter.
func (this *baseRouter) Prepare() {
if utils.IsProMode {
} else {
utils.AppJsVer = beego.Date(time.Now(), "YmdHis")
utils.AppCssVer = beego.Date(time.Now(), "YmdHis")
}
// Setting properties.
this.Data["AppDescription"] = utils.AppDescription
this.Data["AppKeywords"] = utils.AppKeywords
this.Data["AppName"] = utils.AppName
this.Data["AppVer"] = utils.AppVer
this.Data["AppUrl"] = utils.AppUrl
this.Data["AppJsVer"] = utils.AppJsVer
this.Data["AppCssVer"] = utils.AppCssVer
this.Data["IsProMode"] = utils.IsProMode
this.Data["IsBeta"] = utils.IsBeta
// Setting language version.
if len(langTypes) == 0 {
// Initialize languages.
langs := strings.Split(utils.Cfg.MustValue("lang", "types"), "|")
names := strings.Split(utils.Cfg.MustValue("lang", "names"), "|")
langTypes = make([]*langType, 0, len(langs))
for i, v := range langs {
langTypes = append(langTypes, &langType{
Lang: v,
Name: names[i],
})
}
}
isNeedRedir, langVer := setLangVer(this.Ctx, this.Input(), this.Data)
this.Locale.CurrentLocale = langVer
// Redirect to make URL clean.
if isNeedRedir {
i := strings.Index(this.Ctx.Request.RequestURI, "?")
this.Redirect(this.Ctx.Request.RequestURI[:i], 302)
}
}
开发者ID:sirithink,项目名称:beebbs,代码行数:41,代码来源:router.go
示例10: GetIndexJsonStr
//获取日历json数据
func (this *IndexModel) GetIndexJsonStr(uid int) (j []TaskJson) {
var work []Memberwork
//var json_str, fuhao string
db.Raw("select * from "+this.tableName+" where admin_uid=? order by start desc limit 50", uid).QueryRows(&work)
var jsonData []TaskJson
//fmt.Println(times)
for _, v := range work {
jsons := TaskJson{}
jsons.Color = this.GetTaskColor(v.Task_type)
jsons.Id = v.Id
jsons.Title = v.Title
times := beego.Date(time.Unix(v.Start, 0), "Y-m-d H:i:s")
jsons.Start = times
if v.End > 0 {
timee := beego.Date(time.Unix(v.End, 0), "Y-m-d H:i:s")
jsons.End = timee
}
jsonData = append(jsonData, jsons)
}
return jsonData
}
开发者ID:wuxinchaliu,项目名称:go-workadmin,代码行数:23,代码来源:index.go
示例11: Post
func (this *AddBlogController) Post() {
this.Ctx.Request.ParseForm()
title := this.Ctx.Request.Form.Get("title")
content := this.Ctx.Request.Form.Get("content")
//打印生成日志
defer utils.Info("addblog: ", "title:"+title, "content:"+content)
var data models.Blogs
data.Title = title
data.Content = content
//获取系统当前时间
now := beego.Date(time.Now(), "Y-m-d H:i:s")
data.Created = now
models.InsertBlogs(data)
this.Ctx.Redirect(302, "/admin/index")
}
开发者ID:huwenshu,项目名称:blogs,代码行数:15,代码来源:addblog.go
示例12: timesince
func timesince(lang string, t time.Time) string {
now := time.Now()
seconds := int(now.Sub(t).Seconds())
if seconds < 60 {
return i18n.Tr(lang, "seconds_ago", seconds)
} else if seconds < 60*60 {
return i18n.Tr(lang, "minutes_ago", seconds/60)
} else if seconds < 60*60*24 {
return i18n.Tr(lang, "hours_ago", seconds/(60*60))
} else if seconds < 60*60*24*100 {
return i18n.Tr(lang, "days_ago", seconds/(60*60*24))
} else {
return beego.Date(t, DateFormat)
}
}
开发者ID:supermouseno1,项目名称:wetalk,代码行数:15,代码来源:template.go
示例13: timesince
func timesince(lang string, t time.Time) string {
seconds := int(time.Since(t).Seconds())
switch {
case seconds < 60:
return i18n.Tr(lang, "seconds_ago", seconds)
case seconds < 60*60:
return i18n.Tr(lang, "minutes_ago", seconds/60)
case seconds < 60*60*24:
return i18n.Tr(lang, "hours_ago", seconds/(60*60))
case seconds < 60*60*24*100:
return i18n.Tr(lang, "days_ago", seconds/(60*60*24))
default:
return beego.Date(t, setting.DateFormat)
}
}
开发者ID:yubo,项目名称:falcon,代码行数:15,代码来源:template.go
示例14: Post
func (this *RegController) Post() {
this.TplNames = "reg.tpl"
this.Ctx.Request.ParseForm()
username := this.Ctx.Request.Form.Get("username")
password := this.Ctx.Request.Form.Get("password")
usererr := checkUsername(username)
fmt.Println(usererr)
if usererr == false {
this.Data["UsernameErr"] = "Username error, Please to again"
return
}
passerr := checkPassword(password)
if passerr == false {
this.Data["PasswordErr"] = "Password error, Please to again"
return
}
md5Password := md5.New()
io.WriteString(md5Password, password)
buffer := bytes.NewBuffer(nil)
fmt.Fprintf(buffer, "%x", md5Password.Sum(nil))
newPass := buffer.String()
now := beego.Date(time.Now(), "Y-m-d H:i:s")
userInfo := models.GetUserInfo(username)
if userInfo.Username == "" {
var users models.User
users.Username = username
users.Password = newPass
users.Created = now
users.Last_logintime = now
models.AddUser(users)
//登录成功设置session
sess := this.StartSession()
sess.Set("uid", userInfo.Id)
sess.Set("uname", userInfo.Username)
this.Ctx.Redirect(302, "/")
} else {
this.Data["UsernameErr"] = "User already exists"
}
}
开发者ID:huwenshu,项目名称:blogs,代码行数:46,代码来源:reg.go
示例15: Post
func (this *EditBlogController) Post() {
this.Ctx.Request.ParseForm()
id_str := this.Ctx.Request.Form.Get("id")
id, _ := strconv.Atoi(id_str)
blogInfo := models.GetBlogInfoById(id)
title := this.Ctx.Request.Form.Get("title")
content := this.Ctx.Request.Form.Get("content")
blogInfo.Title = title
blogInfo.Content = content
//打印生成日志
defer utils.Info("editBlog: ", "id:"+id_str, "title:"+title, "content:"+content)
//获取系统当前时间
now := beego.Date(time.Now(), "Y-m-d H:i:s")
blogInfo.Created = now
models.UpdateBlogInfo(blogInfo)
this.Ctx.Redirect(302, "/admin/index")
}
开发者ID:huwenshu,项目名称:blogs,代码行数:17,代码来源:editblog.go
示例16: Post
func (self *AvatarController) Post() {
result := make([]interface{}, 2)
result[0] = 1
result[1] = ""
defer func() {
self.Data["json"] = &result
self.ServeJson()
}()
//
f, h, err := self.GetFile("avatar")
if err != nil {
fmt.Println("getfile err ", err)
}
fmt.Println("filename:", h.Filename)
defer f.Close()
//
ext := h.Filename[strings.LastIndex(h.Filename, ".")+1:]
path := "upload/avatar/" + beego.Date(time.Now(), "y/m/d/h/")
os.MkdirAll(path, 0744)
tofile := path + strconv.Itoa(int(self.Uid)) + "." + ext
tf, err := os.OpenFile(tofile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
fmt.Println("write failed:", err)
return
}
defer tf.Close()
io.Copy(tf, f)
if self.U.Avatar != "" && self.U.Avatar != setting.Default_Avatar {
os.Remove(self.U.Avatar[1:])
}
self.U.Avatar = "/" + tofile
self.U.Update("Avatar")
self.SetSession("useravatar", self.U.Avatar)
//
result[0] = 0
result[1] = self.U.Avatar
}
开发者ID:wcreate,项目名称:lawoto,代码行数:43,代码来源:avatar.go
示例17: GetSunday
func (this *Point) GetSunday(t time.Time) string {
//t := time.Now()
week := t.Weekday().String()
var monday string
switch week {
case "Sunday":
case "Monday":
t = t.AddDate(0, 0, 6)
case "Tuesday":
t = t.AddDate(0, 0, 5)
case "Wednesday":
t = t.AddDate(0, 0, 4)
case "Thursday":
t = t.AddDate(0, 0, 3)
case "Friday":
t = t.AddDate(0, 0, 2)
case "Saturday":
t = t.AddDate(0, 0, 1)
}
//monday = t.Format(t_layout)
monday = beego.Date(t, "Y-m-d")
return monday
}
开发者ID:zengcheng,项目名称:sfs,代码行数:23,代码来源:point.go
示例18: datetime
func datetime(t time.Time) string {
return beego.Date(t, DateTimeFormat)
}
开发者ID:supermouseno1,项目名称:wetalk,代码行数:3,代码来源:template.go
示例19: Run
func (j *Job) Run() {
defer func() {
if err := recover(); err != nil {
beego.Error(err, "\n", string(debug.Stack()))
}
}()
t := time.Now()
if j.Concurrent {
j.running.Lock()
defer j.running.Unlock()
}
if workPool != nil {
workPool <- true
defer func() {
<-workPool
}()
}
j.status = 1
defer func() {
j.status = 0
}()
bout, berr, err := j.runFunc()
ut := time.Now().Sub(t) / time.Millisecond
// 插入日志
log := new(models.TaskLog)
log.TaskId = j.id
log.Output = string(bout)
log.Error = string(berr)
log.ProcessTime = int(ut)
log.CreateTime = t.Unix()
if err != nil {
log.Status = -1
log.Error = err.Error() + ":" + string(berr)
}
models.TaskLogAdd(log)
// 更新上次执行时间
j.task.PrevTime = t.Unix()
j.task.ExecuteTimes++
j.task.Update()
// 发送邮件通知
if (j.task.Notify == 1 && err != nil) || j.task.Notify == 2 {
user, uerr := models.UserGetById(j.task.UserId)
if uerr != nil {
return
}
title := ""
if err != nil {
title = fmt.Sprintf("任务执行结果通知 #%d: %s", j.task.Id, "失败")
} else {
title = fmt.Sprintf("任务执行结果通知 #%d: %s", j.task.Id, "成功")
}
data := make(map[string]interface{})
data["task_id"] = j.task.Id
data["username"] = user.UserName
data["task_name"] = j.task.TaskName
data["start_time"] = beego.Date(t, "Y-m-d H:i:s")
data["process_time"] = float64(ut) / 1000
if err != nil {
data["status"] = "失败(" + err.Error() + ")"
data["output"] = string(berr)
} else {
data["status"] = "成功"
data["output"] = string(bout)
}
content := new(bytes.Buffer)
mailTpl.Execute(content, data)
ccList := make([]string, 0)
if j.task.NotifyEmail != "" {
ccList = strings.Split(j.task.NotifyEmail, "\n")
}
if !mail.SendMail(user.Email, user.UserName, title, content.String(), ccList) {
beego.Error("发送邮件超时:", user.Email)
}
}
}
开发者ID:huncent,项目名称:webcron,代码行数:86,代码来源:job.go
示例20: datetimes
func datetimes(t time.Time) string {
return beego.Date(t, setting.DateTimeShortFormat)
}
开发者ID:yubo,项目名称:falcon,代码行数:3,代码来源:template.go
注:本文中的github.com/astaxie/beego.Date函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论