Package gview: build-in function 'date' supports printing current datetime.

This commit is contained in:
John
2018-12-05 15:48:15 +08:00
parent 431e1051b8
commit 83f5a9d34e
3 changed files with 11 additions and 4 deletions

View File

@ -290,8 +290,14 @@ func (view *View) funcUrlDecode(url interface{}) string {
}
// 模板内置方法date
func (view *View) funcDate(format string, timestamp interface{}) string {
return gtime.NewFromTimeStamp(gconv.Int64(timestamp)).Format(format)
func (view *View) funcDate(format string, timestamp...interface{}) string {
t := int64(0)
if len(timestamp) > 0 {
t = gconv.Int64(timestamp[0])
} else {
t = gtime.Millisecond()
}
return gtime.NewFromTimeStamp(t).Format(format)
}
// 模板内置方法compare

View File

@ -502,10 +502,10 @@ func main() {
//update1()
//update2()
//update3()
//linkopSelect1()
linkopSelect1()
//linkopSelect2()
//linkopSelect3()
linkopCount1()
//linkopCount1()
//linkopUpdate1()
//linkopUpdate2()
//linkopUpdate3()

View File

@ -14,6 +14,7 @@ func main() {
{{"https%3A%2F%2Fgfer.me"|urldecode}}
{{1540822968 | date "Y-m-d"}}
{{"1540822968" | date "Y-m-d H:i:s"}}
{{date "Y-m-d H:i:s"}}
{{compare "A" "B"}}
{{compare "1" "2"}}
{{compare 2 1}}