在所有平台上获取全球UTC时间戳

发布于 2025-01-20 18:24:52 字数 608 浏览 2 评论 0原文

我正在尝试在客户端和Python的服务器端为我的程序提供当前的时间戳。但是,我的朋友们和我自己在一起都有问题。我已经尝试过两次同步,并尝试了许多不同的方法来将当前时间作为全球同步的UTC。

这是我尝试的,结果无效。

  1.  导入DateTime
    dateTime.dateTime.utcnow().timestamp()
     
  2.  导入箭头
    arrow.now()。时间戳()
     
  3.  导入时间
    time.time()
     
  4.  来自DateTime Import DateTime,TimeDelta
    进口时间
    unixTime = time.mktime(dateTime.now())
     
  5.  来自DateTime Import DateTime
    导入日历
    d = dateTime.utcnow()
    unixTime = calendar.timegm(d.utctimetuple())
     

以及无数的方法。

I am trying to get the current timestamp for my program on both the client side, and the server side in python. However, my friends, along with myself, have problems. I have tried syncing both times, and tries numerous different methods to get the current time as UTC that is globally synced.

Here is what I've tried, with an invalid outcome.

  1. import datetime
    datetime.datetime.utcnow().timestamp()
    
  2. import arrow
    arrow.now().timestamp()
    
  3. import time
    time.time()
    
  4. from datetime import datetime, timedelta
    import time
    unixtime = time.mktime(datetime.now())
    
  5. from datetime import datetime
    import calendar
    d = datetime.utcnow()
    unixtime = calendar.timegm(d.utctimetuple())
    

Along with countless more methods.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文