一般在获取到时间字符串,需要将时间字符串格式化为golang的”time.Time”对象的时候,通常有2个函数,分别是。
time.Parse(layout, value string) (Time, error)
time.ParseInLocation(layout, value string, loc *Location) (Time, error)
两个函数相比,不一样的地方在于,Parse()函数解析的时候,会默为UTC时间,获取的Time对象转换为Unix()对象后,会比当前时间
1. flag常用函数
无论是c语言还是golang语言或是其他语言,启动应用程序时都可以带一些参数,然后系统根据传入的参数进行特点的工作。如:./main -mode online -model bert_ch. 在Go中可以方便地使用flag模块进行命令行参数解析。
// 解析字符串
type string string
func String(name string, value string, usage string) *string
// 解析整数变量
type int int
f
在 golang 中不能直接用 len 函数来统计字符串长度,查看了下源码发现字符串是以 UTF-8 为格式存储的,说明 len 函数是取得包含 byte 的个数
// string is the set of all strings of 8-bit bytes, conventionally but not
// necessarily representing UTF-8-encoded text. A string may be empty, but
// not nil. Value