1 Star 1 Fork 0

wulala乌啦啦 / hwpack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
time.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
package utils
import (
"time"
"gitee.com/wulalade/hwpack/ntp"
"github.com/gogf/gf/os/gproc"
)
//获取两个时间的间隔
func GetTimeInterval(startTime time.Time, endTime time.Time) int64 {
return int64(((endTime.UnixNano()) / 1000000) - ((startTime.UnixNano()) / 1000000))
}
//获取当前系统时间,返回int64
func GetCurrentTime() int64 {
now_time := time.Now().UnixNano() / int64(time.Millisecond)
return now_time
}
//获取两个时间间隔,返回int64
func GetInterval(lasttime int64) int64 {
return int64(GetCurrentTime() - lasttime)
}
//输入time.Time 获取两个时间间隔,返回int64
func GetExpendTime(startTime time.Time) int64 {
return int64(time.Since(startTime) / 1000000)
}
//通过ntp获取系统时间
func GetSetSystem(url string) bool {
ntpUrl := "ntp.aliyun.com"
if url != "" {
ntpUrl = url
}
ntpTime, err := ntp.Time(ntpUrl)
//fmt.Println("dateTime : ", ntpTime, " , ", err)
if err == nil {
//ntpTime.Format("2006-01-02 15:04:05")
addTime := ntpTime.Add(time.Duration(32/4) * time.Hour)
ntpTimeStr := addTime.Format("2006-01-02 15:04:05")
SetSystemTime(ntpTimeStr)
return true
}
return false
}
//设置系统时间
func SetSystemTime(dateTime string) {
gproc.ShellExec(`date -s "` + dateTime + `"`)
SetTimeToHardSystem()
}
//把当前时间写入硬件系统
func SetTimeToHardSystem() {
gproc.ShellExec(`hwclock -w`)
}
func RebootSystem() {
gproc.ShellExec(`reboot`)
}
1
https://gitee.com/wulalade/hwpack.git
git@gitee.com:wulalade/hwpack.git
wulalade
hwpack
hwpack
d22efa2ac7c9

搜索帮助