Go语言中文网 为您找到相关结果 11

golang utc时间转本地时间

代码如下 now := time.Now() year, mon, day := now.UTC().Date() hour, min, sec := now.UTC().Clock() zone, _ := now.UTC().Zone() fmt.Printf("UTC 时间是 %d-%d-%d %02d:%02d:%02d %s\n", year, mon, day, hour, min, sec, zone) year, mon, day = now.Date() hour, min, sec = now.Clock() zone, _ = now.Zone() fmt.Printf("本地时间是 %d-%d-%d %02d:%02d:%02d %s\n", year, mon, d...阅读全文

博文 2014-10-04 19:27:37 别人说我名字很长

Go语言把IP转为int存储.节省空间提高索引速度

package main import ( "errors" "fmt" "strconv" "strings" ) type IntIP struct { IP string Intip int } func main() { var x *IntIP = &IntIP{IP: "192.168.1.1"} fmt.Println(x) x.ToIntIp() fmt.Println(*x) } func (self *IntIP) String() string { return self.IP } func (self *IntIP) ToIntIp() (int, error) { Intip, err := ConvertToIntIP(self.IP) if err != nil...阅读全文

博文 2015-12-23 22:00:04 fyxichen

Golang Float高精度计算,无误差

Golang Float乘Float高精度,转Int高精度。使用big.FloatbigF1 := new(big.Float).SetFloat64(f1)bigF2 := new(big.Float).SetFloat64(f2)mul := new(big.Float).Mul(bigF1, bigF2)转Int,先用上面的方法转为big.Float,再用.String转为字符串。new(big.Int).SetString(bigFloat, 10) // 即可转为big.Int// big.Int可转为常用的int类型。// big.Float可转为常用的Float类型。// big.Float不能直接转为Int类型...阅读全文

博文 2020-01-12 00:32:42 VANCY_2ddc

[求助]golang中 哈希加密:mac.Sum(nil) 后的结果如何转为普通字符串?

``` // Original key 均为普通字符串 key := []byte(Original) mac := hmac.New(sha1.New, key) mac.Write([]byte(SecretKey)) SignTmp := mac.Sum(nil) fmt.Printf("%x", mac.Sum(nil)) // 正常打印 cb679a19c10ea9153da5281e88fb34fa145b3174 ``` 如上,然后我尝试将其转换为字符串 ``` tmp := []byte(SignTmp[:]) result := string([]byte(tmp[:])) //result变为乱码 ``` 发现resul...阅读全文