Skip to main content

Components

Data Structures

GoFrame provides several commonly used data structures such as lists, queues, sets, maps, etc. For detailed information, refer to the official documentation.

Time

Current Time

t := gtime.Now()
t := gtime.Date()
t := gtime.Datetime()

Creating Time Objects

t := gtime.New("2023-11-03 21:45:22")

The parameter can be a string, timestamp, or time object, etc.

t := gtime.NewFromStr("2023-11-03 21:50:25")
t, err := gtime.StrToTime("2023-11-03 21:50:25")

Converts a string to a time object; see supported time formats in the Time Management/Utility Methods section of the documentation.

Setting Time Zone

gtime.SetTimeZone("Asia/Tokyo")
t := gtime.Now()

Timestamps

t1 := gtime.Timestamp()
t2 := gtime.TimestampMilli()
t3 := gtime.TimestampMicro()
t4 := gtime.TimestampNano()

Returns as int64 type; can also return as a string type.

t1 := gtime.TimestampStr()
t2 := gtime.TimestampMilliStr()
t3 := gtime.TimestampMicroStr()
t4 := gtime.TimestampNanoStr()

Formatting Date Data

Formats a date into the specified format; see formatting symbols in the Time Management/Date Formatting section of the documentation.

t := gtime.Now()
req.Response.Writeln(t.Format("Y-m-d H:i:s"))
req.Response.Writeln(t.Format("YmdHis"))

Getting Year, Month, Day, Hour, Minute, Second

t := gtime.Now()
req.Response.Writeln(t.Year())
req.Response.Writeln(t.Month())
req.Response.Writeln(t.Day())
req.Response.Writeln(t.Hour())
req.Response.Writeln(t.Minute())
req.Response.Writeln(t.Second())

For more methods, see the Time Management/Method Introduction section of the documentation.

Random Numbers

Random Integer

n := grand.Intn(100)

Returns a random number between 0 inclusive and 100 exclusive.

n := grand.N(100, 999)

Returns a random number between 100 inclusive and 999 inclusive.

Random Strings

s := grand.S(10)
s := grand.S(10, true)

Returns a random alphanumeric string of the specified length; the second parameter true includes special characters.

s := grand.Digits(10)

Returns a random numeric string of the specified length.

s := grand.Letters(10)

Returns a random alphabetic string of the specified length.

s := grand.Symbols(10)

Returns a random string of special characters of the specified length.

s := grand.Str("日照香炉生紫烟,遥看瀑布挂前川。Oh Yeah", 5)

Returns a specified number of characters randomly selected from the given string, which can include Chinese characters.

Global Unique Identifier

s := guid.S()