加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Go 一些简要的实用 代码片段

发布时间:2020-12-16 09:45:09 所属栏目:大数据 来源:网络整理
导读:当前时间 + 常规格式化,引用 “time” ts := time.Now().Format("2006-01-02 15:04:05.000") // 2017-10-26 17:32:57.871 字符串转时间 tx := time.Parse("2006-01-02 15:04:05.000","2017-10-26 18:02:01.234")//fmt . Println ( tx . Nanosecond () )= 234

当前时间 + 常规格式化,引用 “time”
ts := time.Now().Format("2006-01-02 15:04:05.000") // 2017-10-26 17:32:57.871
字符串转时间
tx := time.Parse("2006-01-02 15:04:05.000","2017-10-26 18:02:01.234")//fmt.Println( tx.Nanosecond() )=234000000

数值转换字符串
strconv.Itoa(5) //转int一类
strconv.FormatFloat(254.109,'f',-1,64) //转浮点数一类
字符串转数字
strconv.ParseFloat(s string,bitSize int)(f float64,err error)
strconv.Atoi(s string) (i int,err error)

类型断言(类型判断) x 是 接口 interface() v,ok:=x.([]int) // x.(uint),x.(float64) 等等 if ok{ ... }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读