import arrow
def isLeapYear(years):
'''
通过判断闰年,获取年份years下一年的总天数
:param years: 年份,int
:return:days_sum,一年的总天数
'''
# 断言:年份不为整数时,抛出异常。
assert isinstance(years, int), "请输入整数年,如 2018" if ((years % 4 == 0 and years % 100 != 0) or (years % 400 == 0)): # 判断是否是闰年
# print(years, "是闰年")
days_sum = 366
return days_sum
else:
# print(years, '不是闰年')
days_sum = 365
return days_sum def getAllDayPerYear(years):
'''
获取一年的所有日期
:param years:年份
:return:全部日期列表
'''
start_date = '%s-1-1' % years
a = 0
all_date_list = []
days_sum = isLeapYear(int(years))
print()
while a < days_sum:
b = arrow.get(start_date).shift(days=a).format("YYYY-MM-DD")
a += 1
all_date_list.append(b)
# print(all_date_list)
return all_date_list if __name__ == '__main__':
# years = "2001"
# years = int(years)
# # 通过判断闰年,获取一年的总天数
# days_sum = isLeapYear(years) # 获取一年的所有日期
all_date_list = getAllDayPerYear(years)
tzinfo

获取tzinfo的的Arrow对象。

>>> arw=arrow.utcnow()
>>> arw.tzinfo
tzutc()
datetime

返回Arrow对象的日期时间表示形式。

>>> arw=arrow.utcnow()
>>> arw.datetime
datetime.datetime(2019, 1, 24, 16, 35, 27, 276649, tzinfo=tzutc())
naive

返回Arrow 对象的简单日期时间表示。

>>> nairobi = arrow.now('Africa/Nairobi')
>>> nairobi
<Arrow [2019-01-23T19:27:12.297999+03:00]>
>>> nairobi.naive
datetime.datetime(2019, 1, 23, 19, 27, 12, 297999)
timestamp

Arrow以UTC时间形式返回对象的时间戳表示形式。

>>> arrow.utcnow().timestamp
1548260567
float_timestamp

Arrow 以UTC时间形式返回对象的浮点表示形式。

>>> arrow.utcnow().float_timestamp
1548260516.830896
clone()

返回Arrow从当前对象克隆的新对象。

>>> arw = arrow.utcnow()
>>> cloned = arw.clone()
replace(**kwargs)

返回具有Arrow根据输入更新的属性的新对象。

使用属性名称绝对设置其值:

>>> import arrow
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2013-05-11T22:27:34.787885+00:00]>
>>> arw.replace(year=2014, month=6)
<Arrow [2014-06-11T22:27:34.787885+00:00]>

您还可以使用时区表达式替换时区而不进行转换 :

>>> arw.replace(tzinfo=tz.tzlocal())
<Arrow [2013-05-11T22:27:34.787885-07:00]>
shift(**kwargs)

返回具有Arrow根据输入更新的属性的新对象。

使用多个属性名称相对地移动它们的当前值:

>>> import arrow
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2013-05-11T22:27:34.787885+00:00]>
>>> arw.shift(years=1, months=-1)
<Arrow [2014-04-11T22:27:34.787885+00:00]>

星期几相对移位可以使用Python的工作日数字(星期一= 0,星期二= 1 ...星期日= 6)或使用dateutil.relativedelta的日期实例(MO,TU ... SU)。使用工作日数字时,返回的日期将始终大于或等于开始日期。

使用上面的代码(这是一个星期六)并要求它转移到星期六:

>>> arw.shift(weekday=5)
<Arrow [2013-05-11T22:27:34.787885+00:00]>

在要求周一时:

>>> arw.shift(weekday=0)
<Arrow [2013-05-13T22:27:34.787885+00:00]>
to(tz)

返回一个Arrow转换为目标时区的新对象。

>>> utc = arrow.utcnow()Usage:

>>> utc
<Arrow [2013-05-09T03:49:12.311072+00:00]> >>> utc.to('US/Pacific')
<Arrow [2013-05-08T20:49:12.311072-07:00]> >>> utc.to(tz.tzlocal())
<Arrow [2013-05-08T20:49:12.311072-07:00]> >>> utc.to('-07:00')
<Arrow [2013-05-08T20:49:12.311072-07:00]> >>> utc.to('local')
<Arrow [2013-05-08T20:49:12.311072-07:00]> >>> utc.to('local').to('utc')
<Arrow [2013-05-09T03:49:12.311072+00:00]>
span(framecount=1)

返回两个新Arrow对象,表示Arrow给定时间范围内对象的时间跨度。

支持的帧值:年,季度,月,周,日,小时,分钟,秒。

>>> arrow.utcnow()
<Arrow [2013-05-09T03:32:36.186203+00:00]> >>> arrow.utcnow().span('hour')
(<Arrow [2013-05-09T03:00:00+00:00]>, <Arrow [2013-05-09T03:59:59.999999+00:00]>) >>> arrow.utcnow().span('day')
(<Arrow [2013-05-09T00:00:00+00:00]>, <Arrow [2013-05-09T23:59:59.999999+00:00]>) >>> arrow.utcnow().span('day', count=2)
(<Arrow [2013-05-09T00:00:00+00:00]>, <Arrow [2013-05-10T23:59:59.999999+00:00]>)
floor(frame)

返回一个新Arrow对象,表示Arrow给定时间范围内对象的时间跨度的“下限” 。相当于返回的2元组中的第一个元素 span

>>> arrow.utcnow().floor('hour')Usage:

<Arrow [2013-05-09T03:00:00+00:00]>
ceil(frame)

返回一个新Arrow对象,表示Arrow给定时间范围内对象的时间跨度的“上限” 。相当于返回的2元组中的第二个元素 span

>>> arrow.utcnow().ceil('hour')Usage:

<Arrow [2013-05-09T03:59:59.999999+00:00]>
format(fmt='YYYY-MM-DD HH:mm:ssZZ'locale='en_us')

返回Arrow对象的字符串表示形式,根据格式字符串进行格式化。

>>> arrow.utcnow().format('YYYY-MM-DD HH:mm:ss ZZ')Usage:

'2013-05-09 03:56:47 -00:00'

>>> arrow.utcnow().format('X')
'1368071882' >>> arrow.utcnow().format('MMMM DD, YYYY')
'May 09, 2013' >>> arrow.utcnow().format()
'2013-05-09 03:56:47 -00:00'
humanize(other=Nonelocale='en_us'only_distance=Falsegranularity='auto')

返回相对时间差异的本地化人性化表示。

>>> earlier = arrow.utcnow().shift(hours=-2)Usage:

>>> earlier.humanize()
'2 hours ago' >>> later = earlier.shift(hours=4)
>>> later.humanize(earlier)
'in 4 hours'
date()

返回date具有相同年,月和日的对象。

>>> arrow.utcnow().date()
datetime.date(2019, 1, 23)
time()

返回time具有相同小时,分钟,秒,微秒的对象。

>>> arrow.utcnow().time()
datetime.time(12, 15, 34, 68352)
timetz()

返回time具有相同小时,分钟,秒,微秒和tzinfo的对象。

>>> arrow.utcnow().timetz()
datetime.time(12, 5, 18, 298893, tzinfo=tzutc())
astimezone(tz)

返回一个datetime转换为指定时区的对象。

>>> pacific=arrow.now('US/Pacific')Usage:

>>> nyc=arrow.now('America/New_York').tzinfo
>>> pacific.astimezone(nyc)
datetime.datetime(2019, 1, 20, 10, 24, 22, 328172, tzinfo=tzfile('/usr/share/zoneinfo/America/New_York'))
utcoffset()

返回timedelta表示与UTC时间的整数分钟差异的对象。

>>> arrow.now('US/Pacific').utcoffset()
datetime.timedelta(-1, 57600)
dst()

返回夏令时调整。

>>> arrow.utcnow().dst()
datetime.timedelta(0)
timetuple()

在当前时区中返回time.struct_time

>>> arrow.utcnow().timetuple()
time.struct_time(tm_year=2019, tm_mon=1, tm_mday=20, tm_hour=15, tm_min=17, tm_sec=8, tm_wday=6, tm_yday=20, tm_isdst=0)
utctimetuple()

以UTC时间返回 time.struct_time

>>> arrow.utcnow().utctimetuple()
time.struct_time(tm_year=2019, tm_mon=1, tm_mday=19, tm_hour=21, tm_min=41, tm_sec=7, tm_wday=5, tm_yday=19, tm_isdst=0)
toordinal()

返回日期的公历格里高利序数。

>>> arrow.utcnow().toordinal()
737078
weekday()

以整数(0-6)返回星期几。

>>> arrow.utcnow().weekday()
5
isoweekday()

以整数(1-7)返回一周的ISO日期。

>>> arrow.utcnow().isoweekday()
6
isocalendar()

返回3元组(ISO年份,ISO周数,ISO工作日)。

>>> arrow.utcnow().isocalendar()
(2019, 3, 6)
isoformat(sep='T')

返回ISO 8601格式的日期和时间表示。

>>> arrow.utcnow().isoformat()
'2019-01-19T18:30:52.442118+00:00'
ctime()

返回日期和时间的ctime格式表示。

>>> arrow.utcnow().ctime()
'Sat Jan 19 18:26:50 2019'
strftime(format)

datetime.strftime的格式

>>> arrow.utcnow().strftime('%d-%m-%Y %H:%M:%S')Usage:

'23-01-2019 12:28:17'
for_json()

序列for_json化为simplejson 的协议。

>>> arrow.utcnow().for_json()
'2019-01-19T18:25:36.760079+00:00'

Arrow模块生成时间的更多相关文章

  1. python学习之老男孩python全栈第九期_day019知识点总结——collections模块、时间模块、random模块、os模块、sys模块

    一. collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:namedtuple.deque.Counte ...

  2. python-利用faker模块生成测试数据

    Python-利用faker模块生成测试数据 1.前言: Faker模块是一个生成伪数据的第三方模块,他提供了一系列方法,使用非常方便,在做自动化测试时,注册信息,用这个模块生成测试数据就体现了它的好 ...

  3. OrchardNoCMS模块生成工具命令简化

    OrchardNoCMS模块生成工具命令行简化列表:   目前只有codegen feature和cultures三个命令. 对应的都进行了参数简化. 例如:codegen module 简化为cod ...

  4. 把验证码和生成时间负值给$_SESSION[vCode]生成图像给浏览器

    php 图片 中文验证码 <img src="verify_image.php" alt="点此刷新验证码" name="verify_code ...

  5. DAX/PowerBI系列 - 关于时间系列 - 如何用脚本生成时间维度 (Generate Date Dimension)

    跟大家的交流是我的动力. :) DAX/PowerBI系列 - 关于时间系列 - 如何用脚本生成时间维度 (Generate Date Dimension) 难度: ★☆☆☆☆(1星) 适用范围: ★ ...

  6. 【转】Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  7. python模块之时间模块

    一.time模块 表示时间的方式分为: 1时间戳(timestamp) 2格式化化的时间字符串(format string) 3结构化时间(struct_time) import time print ...

  8. Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  9. python常用模块之时间模块

    python常用模块之时间模块 python全栈开发时间模块 上次的博客link:http://futuretechx.com/python-collections/ 接着上次的继续学习: 时间模块 ...

随机推荐

  1. Eclipse 中 SVN 插件的安装与使用

    下载和安装SVN插件 插件在线安装 可以选择在线安装插件的方式,就是使用eclipse里Help菜单的“Install New Software”,通过输入SVN地址,直接下载安装到eclipse里. ...

  2. Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in another process or thread is using this directory.

    1. 问题现象 启动 kafka 时报错:Failed to acquire lock on file .lock in /tmp/kafka-logs. A Kafka instance in an ...

  3. CentOS+Nginx+Supervisor部署ASP.NET Core项目

    对.Net Core的学习和实践,已经进行了一年多的世间,截止目前,微软已经发布.Net Core2.1,关于.NetCore的应用部署的文章比比皆是.今天借此,回顾下.net core环境的部署过程 ...

  4. 选择排序——Selection Sort

    基本思想: 在长度为N的无序数组中,第一次遍历n-1个数,找到最小的数值与第一个元素交换:第二次遍历n-2个数,找到最小的数值与第二个元素交换:...第n-1次遍历,找到最小的数值与第n-1个元素交换 ...

  5. 从零开始学 Web 之 DOM(五)元素的创建

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... +-------------------------------------------------------- ...

  6. Docker入门记1

    Docker是一个部署容器技术,它出现的目的主要解决开发人员在本机开发的时候安装的各类类库等一系列运行程序的包啊库啊,然后把这些引用的第三方类库和操作系统需要的配置打包起来,形成一个原子环境,然后部署 ...

  7. leetcode — merge-k-sorted-lists

    import java.util.ArrayList; import java.util.List; import java.util.PriorityQueue; /** * Source : ht ...

  8. linux搭建sftp服务器

    转自:http://blog.csdn.net/superswordsman/article/details/49331539 最近工作需要用到sftp服务器,被网上各种方法尤其是权限设置问题搞得晕头 ...

  9. bootstrap知识笔记

    .nav>.active>a{ background-color:#0088cc; color:#fff; } /*! * Bootstrap v3.3.7 (http://getboot ...

  10. [算法]PHP随机合并数组并保持原排序

    场景 原有帖子列表A,现需在A中推广新业务B,则需要在A列表中1:1混合B的数据,随机混合,但需保持A和B两列表原来的数据排序.具体参考下面示例的效果. 原理 获知总共元素数量N: for循环N次,取 ...