Python提供两种时间表示方式,一种是时间戳,从1970年1月1日 0时开始。一种是struct_time数组格式,共有9个元素。
import time
print(time.time()) #返回时间戳,从1970年1月1日00:00:00开始。返回值为float。
print(time.ctime()) #输出当前系统时间。
print(time.ctime(time.time()-86400))#当前时间减去一天,返回字符串格式。
print(time.gmtime()) #返回数组形式的struct_time,共九个元素。为UTC时间
# tm_year, tm_mon, tm_mday, tm_hour, tm_min,tm_sec, tm_wday, tm_yday, tm_isdst
now = time.gmtime()
print(now.tm_year)
print(time.localtime()) #返回数组形式的struct_time,共九个元素。为本地时间
print(time.mktime(time.localtime())) #将struct_time转换成字符串格式的时间戳
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime())) #将Struct_time格式转换为指定格式输出。UTC时间。
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())) #将Struct_time格式转换为指定格式输出。本地时间
time.sleep(4) #程序休眠4s
 
import datetime
print(datetime.date.today()) #返回格式:2016-06-07
print(datetime.date.fromtimestamp(time.time()))
print(datetime.datetime.now()) #返回当前时间2016-06-07 15:34:24.228779
print(datetime.datetime.now().timetuple()) #返回struct_time格式的时间
new_date = datetime.datetime.now() + datetime.timedelta(days=10) #比现在加10天
new_date = datetime.datetime.now() + datetime.timedelta(days=-10) #比现在减10天
new_date = datetime.datetime.now() + datetime.timedelta(hours=-10) #比现在减10小时
new_date = datetime.datetime.now() + datetime.timedelta(seconds=120) #比现在+120s
print(new_date)

Python内置模块-time && datatime的更多相关文章

  1. Python内置模块(re+collections+time等模块)

    Python内置模块(re+collections+time等模块) 1. re模块 import re 在python要想使用正则必须借助于模块 re就是其中之一 1.1 findall功能( re ...

  2. python内置模块(4)

    这一部分是python内置模块系列的最后一部分,介绍了一些小巧有用的内置模块. 目录: 1.random 2.shelve 3.getpass 4.zipfile 5.tarfile 6.bisect ...

  3. Python学习笔记【第八篇】:Python内置模块

    什么时模块 Python中的模块其实就是XXX.py 文件 模块分类 Python内置模块(标准库) 自定义模块 第三方模块 使用方法 import 模块名 form 模块名 import 方法名 说 ...

  4. Python内置模块与标准库

    Python内置模块就是标准库(模块)吗?或者说Python的自带string模块是内置模块吗? 答案是:string不是内置模块,它是标准库.也就是说Python内置模块和标准库并不是同一种东西. ...

  5. python内置模块[re]

    python内置模块[re] re模块: python的re模块(Regular Expression正则表达式)提供各种正则表达式的匹配操作,在文本解析.复杂字符串分析和信息提取时是一个非常有用的工 ...

  6. python内置模块[sys,os,os.path,stat]

    python内置模块[sys,os,os.path,stat] 内置模块是python自带功能,在使用内置模块时,需要遵循 先导入在 使用 一.sys 对象 描述 sys.argv 命令行参数获取,返 ...

  7. Python内置模块和第三方模块

    1.Python内置模块和第三方模块 内置模块: Python中,安装好了Python后,本身就带有的库,就叫做Python的内置的库. 内置模块,也被称为Python的标准库. Python 2.x ...

  8. python内置模块collections介绍

    目录 python内置模块collections介绍 1.namedtuple 2.deque 3.defaultdict 4.OrderedDict 5.ChainMap 6.Counter 7.小 ...

  9. Python标准库-datatime和time

    Python标准库-datatime和time 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.标准库datatime 1>.datatime模块 #!/usr/bin/e ...

随机推荐

  1. 【Flutter学习】页面布局之其它布局处理

    一,概述 Flutter中拥有30多种预定义的布局widget,常用的有Container.Padding.Center.Flex.Row.Colum.ListView.GridView.按照< ...

  2. LUOGU P2617 Dynamic Rankings(树状数组套主席树)

    传送门 解题思路 动态区间第\(k\)大,树状数组套主席树模板.树状数组的每个位置的意思的是每棵主席树的根,维护的是一个前缀和.然后询问的时候\(log\)个点一起做前缀和,一起移动.时空复杂度\(O ...

  3. bind-dns服务器搭建

    环境:主服务器上IP为192.168.159.30 安装相关包bind dns服务器  bind-utils提供nslookup dig等命令 yum -y install bind bind-uti ...

  4. The Preliminary Contest for ICPC Asia Shanghai 2019 (B L )

    B. Light bulbs 思路:差分 + 离散化, 好不容易懂了差分却没想到离散化,还是要罗老板出马..... AC代码: #include<bits/stdc++.h> using ...

  5. Jenkins 搭建篇

    1.Jenkins 介绍 自动化运维工具:saltstack.jenkins.等.因为他们的目标一样,为了我们的软件.构建.测试.发布更加的敏捷.频繁.可靠 如果运维对git不熟,是无法做自动化部署. ...

  6. 获取Windows某一目录下的所有文件名

    #include <sys/types.h> #include <dirent.h>     std::vector<std::string> get_all_fi ...

  7. [FW]CLONE_NEWUSER trickery: CVE-2013-1858

    CLONE_NEWUSER trickery: CVE-2013-1858   Recent kernels (3.8+ something) introduced a feature calledu ...

  8. CTU OPEN 2017 Shooting Gallery /// 区间DP

    题目大意: 给定n 给定n个数 选定一个区间留下其他消去 要求区间两端的两个数一样 若成功留下一个区间 则在选定区间的基础上 继续进行上述操作 直到无法再选出这样的区间 求最多操作数 按区间长度由短到 ...

  9. 利用HTML和CSS实现常见的布局

    水平居中的页面布局中最为常见的一种布局形式,多出现于标题,以及内容区域的组织形式,下面介绍四种实现水平居中的方法(注:下面各个实例中实现的是child元素的对齐操作,child元素的父容器是paren ...

  10. 2、eureka注册中心集群

    1. Eureka作为spring cloud的服务发现与注册中心,在整个的微服务体系中,处于核心位置.单机模式下的eureka服务,显然不能满足高可用的实际生产环境,这就要求配置一个能够应对各种突发 ...