arrow是个时间日期库,简洁易用。支持python3.6

https://arrow.readthedocs.io/en/latest/  arrow官网api

https://github.com/crsmithdev/arrow  arrow的GitHub托管的地址

http://www.iplaypy.com/module/m111.html  第三方时间日期库 Python Arrow模块


安装:

pip install arrow

# -*- coding: utf-8 -*-
# coding=utf-8 import arrow # local = utc.to('US/Pacific') # 时区修改
# local = utc.to('Asia/Shanghai') # 时区修改
local = arrow.now('local') # 获取当前时间(推荐)
print(local)
print('-------------') # 时间增减
print(local.replace(years=-1))
print(local.replace(months=-1))
print(local.replace(days=-5))
print(local.replace(hours=-24))
print(local.replace(minutes=-10))
print(local.replace(seconds=-60))
print('-------------') # 字符串转时间
print(arrow.get('2017-10-28T00:00:00+0800'))
# print(arrow.get('2017-10-28', 'YYYY-MM-DD')) # 字符串转时间(不推荐这样用,没有设时区)
print(arrow.get('2017-10-28', 'YYYY-MM-DD', tzinfo='local')) # (推荐)
print(arrow.get('2017-10-28', 'YYYY-MM-DD', tzinfo='Asia/Shanghai')) # 这样也可以
print(arrow.get('2017-10-28 05:30:30', 'YYYY-MM-DD HH:mm:ss', tzinfo='local')) # (推荐)
print('-------------') # 时间戳
print(local.timestamp) # 时间戳
print(arrow.get('', tzinfo='local')) # 时间戳字符串,转换为本时区的时间
# 时间转为字符串,输出(格式化)
print(local.format("YYYY-MM-DD"))
print(local.format("YYYY-MM-DD HH:mm:ss"))
print(local.replace(minutes=-1).humanize(locale='zh')) # 本地化个性时间短语: 刚才,1分钟前,1天前,等  (zh_tw 更多语言的支持,去查看arrow/locales.py)

Arrow主要功能:
1、时区转换
2、简单的时间戳操作
3、时间跨度
4、非常人性化,支持越来越多的语言环境
5、实现datetime接口
6、支持Python 2.6、2.7和3.3
7、默认采用TZ-aware和UTC
8、创建简洁、智能的接口
9、可以轻松更换和改变属性
10、丰富的解析和格式化选项
11、可扩展的工厂架构来支持自定义Arrow派生类型


2017-11-27补充:

判断是否是闰年:

def isLeapYear(year):
if not year % 4 and year % 100 or not year % 400:
return True
return False runyear = []
for i in range(1890, 2150):
if isLeapYear(i):
runyear.append(i)
print(runyear)

...

py库: arrow (时间)的更多相关文章

  1. Lua库之时间和日期操作

    Lua库之时间和日期操作 (2010-02-07 18:41:20) 转载▼ os.time() <== 返回当前系统的日历时间os.date() <== 返回本地化的时间字符串,这里是& ...

  2. tablib把数据导出为Excel、JSON、CSV等格式的Py库(写入数据并导出exl)

    #tablib把数据导出为Excel.JSON.CSV等格式的Py库 #python 3 import tablib #定义列标题 headers = ('1列', '2列', '3列', '4列', ...

  3. python常用标准库(时间模块 time和datetime)

    常用的标准库 time时间模块 import time time -- 获取本地时间戳 时间戳又被称之为是Unix时间戳,原本是在Unix系统中的计时工具. 它的含义是从1970年1月1日(UTC/G ...

  4. python库-Arrow处理时间

    Arrow是一个处理时间的python库,能一键转换dates/times/timestamps等时间格式而不需要大量导致各种时间模块和格式转换函数,十分快捷方便 使用Arrow需要两步转换操作: 1 ...

  5. py库: scrapy (深坑未填)

    scrapy 一个快速高级的屏幕爬取及网页采集框架 http://scrapy.org/ 官网 https://docs.scrapy.org/en/latest/ Scrapy1.4文档 http: ...

  6. py库: pyautogui (自动测试模块,模拟鼠标、键盘动作)

    PyAutoGUI 是一个人性化的跨平台 GUI 自动测试模块 pyautogui 库 2017-10-4 pip install pyautogui python pip.exe install p ...

  7. py库: Tesseract-OCR(图像文字识别)

    http://blog.csdn.net/u012566751/article/details/54094692 Tesseract-OCR入门使用1 http://blog.csdn.net/u01 ...

  8. py库: django (web框架)

    http://www.imooc.com/learn/736 Python-走进Requests库 http://www.imooc.com/learn/790 django入门与实践 http:// ...

  9. python_81_标准库_时间模块

    ''' 标准库: 1.time 时间的三种表示方法:a:时间戳(timestamp) b:格式化的时间字符串 c:元组(struct_time)共九个元素 time.struct_time(tm_ye ...

随机推荐

  1. XenServer7.6命令行导出导入虚拟机(迁移)

    一:命令行方法导出虚拟机(先关闭虚拟机) 1.1:打印虚拟机列表 xe vm-list uuid ( RO) : 43dfac04-515e-7769-b2d2-444d4b7cb198 name-l ...

  2. fullpage 中输入框弹起 页面上移问题处理

    fullpage页面要是有输入框的话  点击输入框 键盘弹出的时候会把输入框也顶起来 页面就会向上移 但是键盘收回的时候页面还是上移的状态 对于这个问题只在android手机上出现  为了解决这个问题 ...

  3. 2--Postman脚本介绍

    Postman是访问各种API的客户端.它的强大之处在于其允许在对某一个request访问的之前和之后分别运行自定义的一段Javascript脚本,可以将数条request连结成一个流程完成一体化测试 ...

  4. Jacobi-Anger expansion

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2017/06/16 适合于自己的关于Jacobi-Anger expansion的推导方法,这里记下来,方便以后查阅. ...

  5. 深入理解使用synchronized同步方法和同步代码块的区别

    一.代码块和方法之间的区别 首先需要知道代码块和方法有什么区别: 构造器和方法块,构造器可以重载也就是说明在创建对象时可以按照不同的构造器来创建,那么构造器是属于对象,而代码块呢他是给所有的对象初始化 ...

  6. 框架tensorflow1

    TensorFlow   1 分类: 1,protocol Buffer  处理结构化数据工具: (xml,json) 2,Bazel        自动化构建工具, 编译: tensor 张量:   ...

  7. JAVA常用设计模式(一、抽象工厂模式)

    抽象工厂模式 抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂.该超级工厂又称为其他工厂的工厂.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最 ...

  8. 【Java】字符串工具类

    import android.annotation.SuppressLint; import java.io.UnsupportedEncodingException; import java.uti ...

  9. LADP(Lightweight Directory Access Protocol)轻量目录访问协议~小知识

    What is LDAP and how does it work(implementation)? LDAP stands for “Lightweight Directory Access Pro ...

  10. MySQL:日期函数、时间函数总结(MySQL 5.X)

    http://www.cnblogs.com/she27/archive/2009/01/16/1377089.html 原文:http://www.51sdj.com/phpcms/picture/ ...