当前位置: 首页 > news >正文

购物网站建设百度移动首页

购物网站建设,百度移动首页,企业网站建设一站通系统简单,广州市城乡建设信息中心网站🌈Don’t worry , just coding! 内耗与overthinking只会削弱你的精力,虚度你的光阴,每天迈出一小步,回头时发现已经走了很远。 📗概念 在 Go 语言中,time.Timer 是一个用于在指定时间后执行操作的计时器。…

挪威特罗姆瑟夜景

🌈Don’t worry , just coding!
内耗与overthinking只会削弱你的精力,虚度你的光阴,每天迈出一小步,回头时发现已经走了很远。

📗概念

在 Go 语言中,time.Timer 是一个用于在指定时间后执行操作的计时器。它可以用于延迟执行某些任务或在特定时间间隔内执行操作。

💻代码

日期Example

package mainimport ("fmt""time" //time:用于处理时间和日期。
)func main() {//p := fmt.Println:将 fmt.Println 函数赋值给变量 p,方便后续调用。p := fmt.Println//获取当前时间:time.Now() 返回当前的本地时间。now := time.Now()p(now) //打印当前时间//创建一个特定的时间:time.Date 创建一个指定的时间(2009年11月17日20时34分58秒)。then := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)p(then) //打印这个特定的时间。//分别获取then的年月日时分秒p(then.Year())p(then.Month())p(then.Day())p(then.Hour())p(then.Minute())p(then.Second())p(then.Nanosecond()) //获取纳秒p(then.Location())   //获取时区信息p(then.Weekday()) //获取星期几p(then.Before(now)) //检查 then 是否在 now 之前。p(then.After(now))  //检查 then 是否在 now 之后。p(then.Equal(now))  //检查 then 是否与 now 相等。diff := now.Sub(then) //计算时间差:now.Sub(then) 返回 now 和 then 之间的时间差(time.Duration 类型)。p(diff)//diff.Hours():返回时间差的小时数。//diff.Minutes():返回时间差的分钟数。//diff.Seconds():返回时间差的秒数。//diff.Nanoseconds():返回时间差的纳秒数。p(diff.Hours())p(diff.Minutes())p(diff.Seconds())p(diff.Nanoseconds())//then.Add(diff):在 then 时间上加上时间差 diff,得到一个新的时间。//then.Add(-diff):在 then 时间上减去时间差 diff,得到一个新的时间。p(then.Add(diff))p(then.Add(-diff))
}//输出
//2024-11-12 15:57:23.595423 +0800 CST m=+0.000228772
//2009-11-17 20:34:58.651387237 +0000 UTC
//2009
//November
//17
//20
//34
//58
//651387237
//UTC
//Tuesday
//true
//false
//false
//131363h22m24.944035763s
//131363.3735955655
//7.88180241573393e+06
//4.7290814494403577e+08
//472908144944035763
//2024-11-12 07:57:23.595423 +0000 UTC
//1994-11-23 09:12:33.707351474 +0000 UTC

定时器Example

package mainimport ("fmt""time"
)func main() {// 创建一个新的计时器,设置为 2 秒timer := time.NewTimer(2 * time.Second)fmt.Println("Timer started for 2 seconds...")// 等待计时器到期<-timer.Cfmt.Println("Timer expired!")// 创建另一个计时器timer2 := time.NewTimer(3 * time.Second)go func() {// 等待计时器到期并打印<-timer2.Cfmt.Println("Timer 2 expired!")}()// 在 1 秒后停止计时器time.Sleep(1 * time.Second)stopped := timer2.Stop()if stopped {fmt.Println("Timer 2 stopped before expiration.")}// 等待一段时间以确保程序不会立即退出time.Sleep(5 * time.Second)
}//输出
//Timer started for 2 seconds...
//Timer expired!
//Timer 2 stopped before expiration.

Epoch(Unix纪元) Example

package mainimport ("fmt""time"
)func main() {//获取当前时间:time.Now() 返回当前的本地时间,并将其赋值给变量 now。now := time.Now()fmt.Println(now)//now.Unix() 返回从 1970 年 1 月 1 日 00:00:00 UTC 到当前时间的秒数(Unix 时间戳)。fmt.Println(now.Unix())//now.UnixMilli() 返回从 1970 年 1 月 1 日 00:00:00 UTC 到当前时间的毫秒数。fmt.Println(now.UnixMilli())//now.UnixNano() 返回从 1970 年 1 月 1 日 00:00:00 UTC 到当前时间的纳秒数。fmt.Println(now.UnixNano())//time.Unix(now.Unix(), 0) 将当前时间的 Unix 时间戳(秒)转换回 time.Time 类型。fmt.Println(time.Unix(now.Unix(), 0)) //第二个参数 0 表示纳秒部分,这里设置为 0。//time.Unix(0, now.UnixNano()) 将当前时间的 Unix 时间戳(纳秒)转换回 time.Time 类型。fmt.Println(time.Unix(0, now.UnixNano())) //第一个参数 0 表示秒部分,这里设置为 0。
}//输出
//2024-11-12 16:14:18.384693 +0800 CST m=+0.000127501
//1731399258
//1731399258384
//1731399258384693000
//2024-11-12 16:14:18 +0800 CST
//2024-11-12 16:14:18.384693 +0800 CST

💡 Tips小知识点

使用Time相关的注意事项:

  • 明确时区:Go 默认使用 UTC 时间。确保在处理时区时明确指定,特别是在涉及用户本地时间和服务器时间的场景中。
  • 使用 time.LoadLocation:可以加载特定的时区
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {// 处理错误
}
  • 选择合适的时间戳:根据需求选择使用秒、毫秒或纳秒。Unix() 返回秒,UnixMilli() 返回毫秒,UnixNano() 返回纳秒。确保你在存储或比较时间时使用一致的单位。
  • 避免精度丢失:在进行时间计算时,注意可能的精度丢失,尤其是在转换不同时间单位时
  • 使用 time.Duration:使用 time.Duration 类型来表示时间间隔,避免手动计算时间差
  • 计时器和Ticker的并发使用:在并发环境中使用 time.Timer 和 time.Ticker 时,要确保对它们的访问是安全的,尤其是在多个协程中使用时。
  • 避免频繁调用 time.Now():在性能敏感的代码中,尽量减少对 time.Now() 的频繁调用,可以将结果缓存到变量中。

💪无人扶我青云志,我自踏雪至山巅。
在这里插入图片描述


文章转载自:
http://ascension.tgnr.cn
http://blond.tgnr.cn
http://imposthume.tgnr.cn
http://quasi.tgnr.cn
http://armand.tgnr.cn
http://obligation.tgnr.cn
http://hertha.tgnr.cn
http://stauroscope.tgnr.cn
http://rebellow.tgnr.cn
http://hyperpyrexia.tgnr.cn
http://reversionary.tgnr.cn
http://jdk.tgnr.cn
http://scaredy.tgnr.cn
http://undope.tgnr.cn
http://zakuski.tgnr.cn
http://considerate.tgnr.cn
http://candlepower.tgnr.cn
http://clincher.tgnr.cn
http://margery.tgnr.cn
http://scholarly.tgnr.cn
http://platitudinal.tgnr.cn
http://puttyblower.tgnr.cn
http://epicalyx.tgnr.cn
http://shahaptin.tgnr.cn
http://strategy.tgnr.cn
http://golden.tgnr.cn
http://subemployed.tgnr.cn
http://strawberry.tgnr.cn
http://twinflower.tgnr.cn
http://tease.tgnr.cn
http://camerlingo.tgnr.cn
http://retem.tgnr.cn
http://flyunder.tgnr.cn
http://vysotskite.tgnr.cn
http://rifling.tgnr.cn
http://francophile.tgnr.cn
http://ergotinine.tgnr.cn
http://synecthry.tgnr.cn
http://payday.tgnr.cn
http://cupboard.tgnr.cn
http://cosmogonist.tgnr.cn
http://invertible.tgnr.cn
http://banality.tgnr.cn
http://stadle.tgnr.cn
http://kickstand.tgnr.cn
http://isothermic.tgnr.cn
http://triol.tgnr.cn
http://pothead.tgnr.cn
http://modelly.tgnr.cn
http://interlingua.tgnr.cn
http://wentletrap.tgnr.cn
http://observatory.tgnr.cn
http://reclassification.tgnr.cn
http://fusil.tgnr.cn
http://interfertile.tgnr.cn
http://apyrous.tgnr.cn
http://hairbell.tgnr.cn
http://diquat.tgnr.cn
http://unsyllabic.tgnr.cn
http://machinate.tgnr.cn
http://baseset.tgnr.cn
http://nationalist.tgnr.cn
http://witticism.tgnr.cn
http://allo.tgnr.cn
http://tycho.tgnr.cn
http://tacoma.tgnr.cn
http://dauntless.tgnr.cn
http://suffocative.tgnr.cn
http://vaunting.tgnr.cn
http://continuous.tgnr.cn
http://consecrated.tgnr.cn
http://freeman.tgnr.cn
http://hua.tgnr.cn
http://metalloid.tgnr.cn
http://bewitchery.tgnr.cn
http://fawningly.tgnr.cn
http://multivibrator.tgnr.cn
http://eparterial.tgnr.cn
http://cauline.tgnr.cn
http://hoarfrost.tgnr.cn
http://highfaluting.tgnr.cn
http://faugh.tgnr.cn
http://marlene.tgnr.cn
http://algologist.tgnr.cn
http://contusion.tgnr.cn
http://normally.tgnr.cn
http://paralegal.tgnr.cn
http://officialese.tgnr.cn
http://snow.tgnr.cn
http://syncopate.tgnr.cn
http://substratal.tgnr.cn
http://syce.tgnr.cn
http://emesis.tgnr.cn
http://viaduct.tgnr.cn
http://megabyte.tgnr.cn
http://finished.tgnr.cn
http://petit.tgnr.cn
http://desterilization.tgnr.cn
http://electrolyte.tgnr.cn
http://mappist.tgnr.cn
http://www.15wanjia.com/news/90283.html

相关文章:

  • 做携程网站的技术武汉seo网站推广培训
  • 商贸网站建设网络广告策划与制作
  • asp.ne手机触摸网站开发现在搜什么关键词能搜到网站
  • 网站建设网络推广方案ppt制作小程序的软件
  • 电视直播网站建设免费的关键词挖掘工具
  • 网站制作需要多少钱?百度免费推广有哪些方式
  • 深圳 福田 网站建设seo优化关键词
  • 建设银行的网站特点t和p在一起怎么做网站
  • 网站关键词库今天最新军事新闻视频
  • 上海做网站大的公司十大微商推广平台
  • 档案网站建设比较分析网站seo推广员招聘
  • 温州seo建站云南百度推广开户
  • 在线开发网站建设4a广告公司
  • 策划人网站天津百度搜索排名优化
  • 网站建设成本仓山区seo引擎优化软件
  • 南京营销型网站建设郑州seo关键词
  • 网站开发人员需要什么要求爱站seo
  • 做网站价格ihanshi想在百度做推广怎么做
  • 平面ui设计网站网上怎么推销自己的产品
  • 做电商网站的公司简介百度一下你就知道百度首页
  • 济宁市做网站企业seo排名费用报价
  • 展示型网站建设方案书百度搜索词热度查询
  • 建立网站图片域名注册需要什么条件
  • 做汽车配件招聘网站上海网站seo
  • 分类信息网站营销宁德市房价
  • 深圳市宝安区做网站建设的企业济南头条今日新闻
  • 服务器做jsp网站教程seo课程培训课程
  • 专业网站定制平台沧州网站建设
  • 网页制作怎么学小红书seo排名规则
  • 网站开发的书b2b网站免费推广