now := time. Now ( )
res1 := now. Day ( )
fmt. Println ( res1)
res2 := fmt. Sprintf ( "%d-%d-%d %d:%d:%d\n" , now. Year ( ) , now. Month ( ) , now. Day ( ) ,
now. Hour ( ) , now. Minute ( ) , now. Second ( ) )
fmt. Println ( res2)
fmt. Println ( time. Millisecond)
fmt. Println ( now. Unix ( ) )
fmt. Println ( now. UnixNano ( ) )
num1 := 100
fmt. Printf ( "num1的类型%T, num1的值=%v, num1值得地址=%v\n" , num1, num1, & num1)
num2 := new ( int )
* num2 = 100
fmt. Printf ( "num2的类型%T, num2的值=%v, num2的地址%v, num2地址指针指向的值=%v" , num2, num2, & num2, * num2)
func judgeHasSuffix ( suffix string ) func ( string ) string {
return func ( prefix string ) string {
if strings. HasSuffix ( prefix, suffix) {
return prefix
} else {
return prefix + suffix
}
}
}
func main ( ) {
res := judgeHasSuffix ( ".jpg" )
var fileName1 string = "34"
fmt. Println ( res ( fileName1) )
}
defer func ( ) {
err := recover ( )
if err != nil {
fmt. Println ( "err=" , err)
}
} ( )
num1 := 10
num2 := 0
res := num1 / num2
fmt. Println ( res)
func readConf ( name string ) ( err error ) {
if name == "config.ini" {
return nil
} else {
return errors. New ( "读取文件错误" )
}
}
func main ( ) {
res := readConf ( "config2.ini" )
if res != nil {
panic ( res)
}
fmt. Println ( "正常运行" )
}