Browse Source

Readable date and time

Vova Tkach 6 years ago
parent
commit
5ca6d8939d
2 changed files with 11 additions and 2 deletions
  1. 5 0
      modules/module_index.go
  2. 6 2
      utils/utils.go

+ 5 - 0
modules/module_index.go

@@ -69,6 +69,11 @@ func (this *Modules) RegisterModule_Index() *Module {
 					DBField:     "datetime",
 					DBExp:       "UNIX_TIMESTAMP(`datetime`)",
 					NameInTable: "Date / Time",
+					CallBack: func(values *[]string) string {
+						t := int64(utils.StrToInt((*values)[3]))
+						return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
+							`<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
+					},
 				},
 				{
 					DBField:     "active",

+ 6 - 2
utils/utils.go

@@ -227,6 +227,10 @@ func GenerateAlias(str string) string {
 	return alias
 }
 
-func UnixTimestampToMySqlDateTime(value int64) string {
-	return time.Unix(value, 0).Format("2006-01-02 15:04:05")
+func UnixTimestampToMySqlDateTime(sec int64) string {
+	return time.Unix(sec, 0).Format("2006-01-02 15:04:05")
+}
+
+func UnixTimestampToFormat(sec int64, format string) string {
+	return time.Unix(sec, 0).Format(format)
 }