带有 utc 的时间戳和任何其他时区都与箭头相同

Timestamp with utc and any other timezone is coming out to be same with arrow

import arrow    
print arrow.utcnow()
print arrow.utcnow().timestamp
print arrow.utcnow().to('Asia/Kolkata')
print arrow.utcnow().to('Asia/Kolkata').timestamp

我需要 'Asia/Kolkata' 时区的时间戳(整数),从 utc 算起 +5:30。

arrow.utcnow()arrow.utcnow().to('Asia/Kolkata') 是不同的,第二个是 +5:30 第一个,正如预期的那样。

然而,arrow.utcnow().timestamparrow.utcnow().to('Asia/Kolkata').timestamp 仍然是一样的。

我确定我在这里遗漏了一些非常基本的东西,但是有人可以解释一下吗?

我认为 "timestamp",根据定义,始终采用 UTC:

The Unix time (or Unix epoch or POSIX time or Unix timestamp) is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds.

如果您采用本地化时间字符串,将其转换为 UTC 日期时间(即加尔各答时间下午 5 点变为 UTC 下午 5 点),那么您可以获得与本地时钟时间相对应的时间戳。示例:

import arrow    
print arrow.utcnow()
print arrow.utcnow().timestamp
kolkata = arrow.utcnow().to('Asia/Kolkata')
print kolkata.replace(tzinfo='UTC').timestamp

时间戳是 UTC,这在 Arrow 文档中也有描述

timestamp

Returns a timestamp representation of the Arrow object, in UTC time.

Arrow 可让您将非 UTC 时间戳转换为箭头时间,但不会让您搬起石头砸自己的脚生成非 UTC 时间戳。

classmethod fromtimestamp(timestamp, tzinfo=None)

Constructs an Arrow object from a timestamp, converted to the given timezone.

Parameters: timestamp – an int or float timestamp, or a str that converts to either. tzinfo – (optional) a tzinfo object. Defaults to local time. Timestamps should always be UTC. If you have a non-UTC timestamp:

arrow.Arrow.utcfromtimestamp(1367900664).replace(tzinfo='US/Pacific') <Arrow [2013-05-07T04:24:24-07:00]>

完整文档在这里:

http://arrow.readthedocs.io/en/latest/