diff --git a/day06/log_demo/log_demo.exe b/day06/log_demo/log_demo.exe new file mode 100644 index 0000000..3abe8ad Binary files /dev/null and b/day06/log_demo/log_demo.exe differ diff --git a/day06/log_demo/main.go b/day06/log_demo/main.go new file mode 100644 index 0000000..58835bb --- /dev/null +++ b/day06/log_demo/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "project/day06/mylogger_test" + "time" +) + +// type logger struct { +// } + +// func Newlog()Logger { +// return Logger{} +// } + +func main() { + // fileObj, err := os.OpenFile("./xx.log", os.O_APPEND|os.O_CREATE, 0644) + // if err != nil { + // fmt.Printf("error:%v", err) + // return + // } + //debug + //trace + //info + //warning + //error + //fatal + + //日志要支持开关 + //日志要有时间、行号、文件名、日志级别、日志信息 + + //日志文件要切割 + log := mylogger_test.NewLog() + for { + log.Debug("这是一条Debug log") + log.Info("这是一条info log") + log.Warning("这是一条warning log") + log.Error("error") + time.Sleep(time.Second * 3) + } +} diff --git a/day06/mylogger_test/console.go b/day06/mylogger_test/console.go new file mode 100644 index 0000000..95a24a1 --- /dev/null +++ b/day06/mylogger_test/console.go @@ -0,0 +1,29 @@ +package mylogger_test + +import "fmt" + +//logger 日志结构体 +type Logger struct { +} + +//Newlog 构造函数 + +func NewLog() Logger { + return Logger{} +} + +func (l Logger) Debug(msg string) { + fmt.Println(msg) +} +func (l Logger) Info(msg string) { + fmt.Println(msg) +} +func (l Logger) Warning(msg string) { + fmt.Println(msg) +} +func (l Logger) Error(msg string) { + fmt.Println(msg) +} +func (l Logger) Fatal(msg string) { + fmt.Println(msg) +} diff --git a/day06/time/main.go b/day06/time/main.go new file mode 100644 index 0000000..a889c1d --- /dev/null +++ b/day06/time/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + now := time.Now() + fmt.Println(now.Year()) + fmt.Println(now) + fmt.Println(now.Date()) + fmt.Println(time.Unix(1564803667, 0)) + + //时间间隔 + fmt.Println(time.Second) + //now +24小时 + fmt.Println(now.Add(24 * time.Millisecond * 1000 * 60 * 60)) + + //格式化时间 + t, _ := time.Parse(time.Stamp, "Jan 11,2024 at 7.12am(PST)") + fmt.Println(time.Stamp) + fmt.Println(t) + //按照对应的格式解析字符串类型的时间 + timeObj, err := time.Parse("2006-01-02", "2019-08-03") + if err != nil { + fmt.Printf("parse time failed,err:%v\n", err) + return + } + fmt.Println(timeObj) + fmt.Println(timeObj.Unix()) + //sub 两个时间相减 + nextYear, err := time.Parse("2006-01-02", "2024-10-11") + if err != nil { + fmt.Printf("parse time failed,err:%v\n", err) + return + } + d := now.Sub(nextYear) + fmt.Println(d) + fmt.Println("------------------") + nextYear1 := nextYear.UTC() + fmt.Println(nextYear1) + fmt.Println("-----------") + time.Sleep(time.Duration(100) * time.Second) + fmt.Println("100s has gone") +} diff --git a/day06/time/time.exe b/day06/time/time.exe new file mode 100644 index 0000000..515d092 Binary files /dev/null and b/day06/time/time.exe differ diff --git a/day06/zone/main.go b/day06/zone/main.go new file mode 100644 index 0000000..6fce08b --- /dev/null +++ b/day06/zone/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "time" +) + +// func f1() { +// } + +func f2() { + now := time.Now() //当前时间 + fmt.Println(now) + + //根据东八区的时区和格式去解析一个字符串格式的时间 + //根据字符串加载时区 + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + if err != nil { + fmt.Printf("locate time failed,err:%v\n", err) + return + } + } + //按照指定时区解析时间 + timeObj, err := time.ParseInLocation("2006-01-02 15:04:05", "2024-10-11 19:59:00", loc) + if err != nil { + fmt.Printf("parse time failed,err:%v\n", err) + return + } + fmt.Println(timeObj) + td := timeObj.Sub(now) + fmt.Println(td) +} + +func main() { + f2() +} diff --git a/day06/zone/zone.exe b/day06/zone/zone.exe new file mode 100644 index 0000000..b17e258 Binary files /dev/null and b/day06/zone/zone.exe differ