本文整理汇总了Python中arrow.Arrow.utcfromtimestamp方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow.utcfromtimestamp方法的具体用法?Python Arrow.utcfromtimestamp怎么用?Python Arrow.utcfromtimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.Arrow
的用法示例。
在下文中一共展示了Arrow.utcfromtimestamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: arrow
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import utcfromtimestamp [as 别名]
def arrow(date=None, tz=None):
if date is None:
return utcnow() if tz is None else now(tz)
else:
if tz is None:
try:
tz = parser.TzinfoParser.parse(date)
return now(tz)
except:
pass
if isinstance(date, (float, int)):
return Arrow.utcfromtimestamp(date)
return Arrow.fromdatetime(date)
else:
tz = parser.TzinfoParser.parse(tz)
return Arrow.fromdatetime(date, tz)
示例2: get
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import utcfromtimestamp [as 别名]
def get(*args, **kwargs):
'''Returns an :class:`Arrow <arrow.Arrow>` object based on flexible inputs.
Usage::
>>> import arrow
**No inputs** to get current UTC time::
>>> arrow.get()
<Arrow [2013-05-08T05:51:43.316458+00:00]>
**One str**, **float**, or **int**, convertible to a floating-point timestamp, to get that timestamp in UTC::
>>> arrow.get(1367992474.293378)
<Arrow [2013-05-08T05:54:34.293378+00:00]>
>>> arrow.get(1367992474)
<Arrow [2013-05-08T05:54:34+00:00]>
>>> arrow.get('1367992474.293378')
<Arrow [2013-05-08T05:54:34.293378+00:00]>
>>> arrow.get('1367992474')
<Arrow [2013-05-08T05:54:34+00:00]>
**One str**, convertible to a timezone, or **tzinfo**, to get the current time in that timezone::
>>> arrow.get('local')
<Arrow [2013-05-07T22:57:11.793643-07:00]>
>>> arrow.get('US/Pacific')
<Arrow [2013-05-07T22:57:15.609802-07:00]>
>>> arrow.get('-07:00')
<Arrow [2013-05-07T22:57:22.777398-07:00]>
>>> arrow.get(tz.tzlocal())
<Arrow [2013-05-07T22:57:28.484717-07:00]>
**One** naive **datetime**, to get that datetime in UTC::
>>> arrow.get(datetime(2013, 5, 5))
<Arrow [2013-05-05T00:00:00+00:00]>
**One** aware **datetime**, to get that datetime::
>>> arrow.get(datetime(2013, 5, 5, tzinfo=tz.tzlocal()))
<Arrow [2013-05-05T00:00:00-07:00]>
**Two** arguments, a naive or aware **datetime**, and a timezone expression (as above)::
>>> arrow.get(datetime(2013, 5, 5), 'US/Pacific')
<Arrow [2013-05-05T00:00:00-07:00]>
**Two** arguments, both **str**, to parse the first according to the format of the second::
>>> arrow.get('2013-05-05 12:30:45', 'YYYY-MM-DD HH:mm:ss')
<Arrow [2013-05-05T12:30:45+00:00]>
**Three or more** arguments, as for the constructor of a **datetime**::
>>> arrow.get(2013, 5, 5, 12, 30, 45)
<Arrow [2013-05-05T12:30:45+00:00]>
'''
arg_count = len(args)
if arg_count == 0:
return Arrow.utcnow()
if arg_count == 1:
arg = args[0]
timestamp = None
try:
timestamp = float(arg)
except:
pass
# (int), (float), (str(int)) or (str(float)) -> from timestamp.
if timestamp is not None:
return Arrow.utcfromtimestamp(timestamp)
# (datetime) -> from datetime.
elif isinstance(arg, datetime):
return Arrow.fromdatetime(arg)
# (tzinfo) -> now, @ tzinfo.
elif isinstance(arg, tzinfo):
return Arrow.now(arg)
# (str) -> now, @ tzinfo.
elif isinstance(arg, str):
_tzinfo = parser.TzinfoParser.parse(arg)
return Arrow.now(_tzinfo)
else:
raise TypeError('Can\'t parse single argument type of \'{0}\''.format(type(arg)))
#.........这里部分代码省略.........