Golang学习笔记

---

runtime包

 获取GORoot

runtime.GOROOT()

获取操作系统

runtime.GOOS()

获取逻辑cpu数量

untime.NumCPU()

设置程序执行的最大cpu数量

```

n: = runtime.GOMAXPROCS(runtime.NumCPU)


```



OS包

os.open()    //*打开文件*  , 只限于读取文件



os.OpenFile(file string, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) // *可读可写* 文件


time 包

t1 := time.Now() //初始化一个时间

s1 := t1.Format("2006年1月2日 15:04:05") //123456 必需使用这个日期来做格式的模板

s2 := t1.Format("2006/01/02")

t2 := time.Date(2008,7,15,16,30,28,0,time.Local) //传入年月日时分秒纳秒时区

fmt.Println(t2)

//获取年月日

year,month,day := t1.Date()

fmt.Println(year,month,day)

//获取时分秒

hour,min,sec := t1.Clock()

fmt.Println(hour min,sec)

//分开获取时间

year2 := t1.Year()

month2 := t1.Month()    //

day2 := t1.Day()    //天

hour2 := t1.Hour()    //时

min2 := t1.Minute()    //分

sec2 := t1.Second()    //秒

Nan2:= t1.Nanosecond()    //纳秒

weekday := t1.Weekday()    //星期

//时间缀

Unix2 := t1.Unix()     //从调用这个方法的时间开始算,往前到1970年1月1日0点0分0秒的时间差值

文件操作

获取文件名

方法一:

srcfile := `C:/Windows/System32/drivers/etc/hosts.ics`

destFile := srcFile[strings.LastIndes(srcFile,"/")+1:]        //通过切片的形式获取,但要预览此路径只是文件夹

fmt.Println(destFile)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容