[英]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.