简体   繁体   English

Python:无论我当前的系统时间如何,如何显示时区 IST 的当前时间

[英]Python: How can i show current time of timezone IST irrespective of my current system time

i tried using import datetime and several other but when i change my System time it show according to my current system time instead actual time我尝试使用 import datetime 和其他几个,但是当我更改系统时间时,它会根据我当前的系统时间而不是实际时间显示

You can use pytz to do so:您可以使用pytz这样做:

import datetime
import pytz
date = datetime.datetime.now()
timezone = pytz.timezone("Asia/Kolkata")
date_ist = timezone.localize(date)

NTP servers are what this is for. NTP 服务器就是这样做的。 You need a clock to reliably get time data.您需要一个时钟来可靠地获取时间数据。 Usually that's the system clock.通常这是系统时钟。 But NTP is good when you want your code to be independent of that.但是当你希望你的代码独立于它时,NTP 是很好的。

ntplib is a library that makes querying these easy ntplib是一个使查询这些变得容易的库

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在python中获取时区的当前时间? - Getting current time with timezone in python? 如何在PyMySQL中编写使用当前系统时间的查询? - How can I write a query that uses the current system time in PyMySQL? 如何使Django为系统区域设置使用正确的当前时间? - How can I make Django use the correct current time for my system locale? 将时区添加到 python 的当前时间戳中 - Add timezone into current time stamp for python 如何在python 2 tkinter中同时显示当前任务的运行状态和更新进度条而不冻结? - How can I show status of current task running and update the progressbar without freezing at same time in python 2 tkinter? 如何获取特定时区的当前时间? - How to get current time in a specific timezone? tornado.ioloop.IOLoop.current().time() 不在我的时区,如何配置时区偏移? - tornado.ioloop.IOLoop.current().time() is not in my timezone, how to configure timezone offset? Python:鉴于当前UTC时间,您如何确定特定时区内一天的开始和结束时间? - Python: Given the current time in UTC, how do you determine the start and end time of the day in a particular timezone? 如何创建一个可变的时间函数,可以在python中选择时间(即不是实际的当前时间)? - How can I create a mutable time function where I can choose the time in python (i.e. not the actual current time)? 如何在 python 中输入当前时间 - How to input current time in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM