标签:表示 get rtu ack orm time append atoi 进制转换
问题package main
import (
"time"
"fmt"
"strconv"
)
func reverse(s string)string{
sLen := len(s)
var sSliRev []byte
for i:=sLen-1;i>=0;i--{
sSliRev = append(sSliRev,s[i])
}
return string(sSliRev)
}
func judge(s string)bool{
n,err := strconv.Atoi(s)
if err != nil{
panic(err)
}
sBin := fmt.Sprintf("%b", n)
sBinRev := reverse(sBin)
if sBin == sBinRev{
return true
}else{
return false
}
}
func main(){
start,err := time.Parse("20060102", "19641010")
if err != nil{
fmt.Println("get start time failed, ", err)
return
}
startUnix := start.Unix()
end,err := time.Parse("20060102", "20200724")
if err != nil{
fmt.Println("get start time failed, ", err)
return
}
endUnix := end.Unix()
days := (endUnix - startUnix) / 86400
var i int64
for i=0;i<=days;i++{
dateUnix := startUnix + i * 86400
date := time.Unix(dateUnix,0).Format("20060102")
if judge(date){
fmt.Println(date)
}
}
}
结果:
19660713
19660905
19770217
19950617
20020505
20130201
时间的遍历稍麻烦一些,进制转换、逆序,然后判断筛选。
标签:表示 get rtu ack orm time append atoi 进制转换
原文地址:http://blog.51cto.com/johnnyloo/2138588