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. eclipse工具类及插件(修改eclipse.ini文件及作者名字)

    https://jingyan.baidu.com/album/9158e0005633c0a254122807.html?picindex=1 (修改eclipse.ini文件及作者名字) http ...

  2. Python编程--类的分析

    一.类的概念 python是面向对象的编程语言,详细来说,我们把一类相同的事物叫做类,其中用相同的属性(其实就是变量描述),里面封装了相同的方法,比如:汽车是一个类,它包括价格.品牌等属性.那么我们如 ...

  3. windows mysql 的myini

    地址 :C:\ProgramData\MySQL\MySQL Server 5.7

  4. python自学第10天,生成器

    列表生成式 print([i*2 for i in range(10)])#这就是列表生成式 #相当于下面的代码 a=[] for i in range(10): a.append(i*2) prin ...

  5. ios中模态弹窗用法及UINavigationController基本用法

    - (void)viewDidLoad { [super viewDidLoad]; //点击按钮跳转 loginViewController *vc=[[loginViewController al ...

  6. 外网ssh内网Linux服务器holer实现

    外网ssh访问内网linux 内网的主机上安装了Linux系统,只能在局域网内访问,怎样从公网也能ssh访问本地Linux服务器? 本文将介绍使用holer实现的具体步骤. 1. 准备工作 1.1 安 ...

  7. yuan的第二次随笔

    第一题: 计算两数的和与差 设计思路: 1:看题目:主函数与函数声明,知道它要你干什么 2:理解与分析:在main中,定义两个实数a,b;要你求两数的和与差 3:解答:通过调用函数sum_diff,指 ...

  8. springboot中get post put delete 请求

    组合注解(RequestMapping的变形) @GetMapping = @RequestMapping(method = RequestMethod.GET) @PostMapping = @Re ...

  9. QT | QT MSVC 2015 + VS 2015开发环境配置及GIT设置

    1.下载: 所有Qt版本的下载地址: http://download.qt.io/archive/qt/ 实际使用了http://download.qt.io/archive/qt/5.7/5.7.1 ...

  10. 学习笔记TF023:下载、缓存、属性字典、惰性属性、覆盖数据流图、资源

    确保目录结构存在.每次创建文件,确保父目录已经存在.确保指定路径全部或部分目录已经存在.创建沿指定路径上不存在目录. 下载函数,如果文件名未指定,从URL解析.下载文件,返回本地文件系统文件名.如果文 ...