模块之time与datetime

import time
print (time.clock())
print(time.process_time()) #测量处理器运算时间
print(time.altzone) #返回utc时间差,以秒计算
print(time.asctime())#返回时间格式
print(time.localtime())#返回本地时间的struct time 对象
print(time.gmtime(time.time()))#返回utc时间的struc时间,与中国本地时间相差8小时,中国是东八区。
print(time.asctime(time.localtime()))#返回时间格式
print(time.ctime())#返回时间格式,与上条相同 string_2_struct = time.strptime("2019/12/19","%Y/%m/%d") #将日期字符品转换成struct时间格式
print(string_2_struct)
string_2_stamp= time.mktime(string_2_struct) #将struct时间对像转换成时间戳 print(time.gmtime(time.time()))#将UTC时间戳转换成struct_time格式
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime() )) #将UTC struct_time 格式转成指定的字符串格式########2019-12-19 14:53:37 #时间的运算(时间加减)
import datetime
print (datetime.datetime.now()) #返回当前时间
print(datetime.date.fromtimestamp(time.time()))#将时间戳直接转成日期格式
print (datetime.datetime.now()+datetime.timedelta(3))#当前时间加3天
print(datetime.datetime.now()+datetime.timedelta(-3))#当前时间减3天
print(datetime.datetime.now()+datetime.timedelta(hours=3))#当前时间加3小时
print(datetime.datetime.now()+datetime.timedelta(minutes=30))#当前时间加30分钟 c_time=datetime.datetime.now()
print(c_time.replace(minute=3,hour=2))#把时间替换成2点3分钟。 打印结果
3e-07
0.109375
-32400
Thu Dec 19 23:32:52 2019
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=23, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
Thu Dec 19 23:32:52 2019
Thu Dec 19 23:32:52 2019
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=353, tm_isdst=-1)
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
2019-12-19 15:32:52
2019-12-19 23:32:52.735813
2019-12-19
2019-12-22 23:32:52.735813
2019-12-16 23:32:52.735813
2019-12-20 02:32:52.735813
2019-12-20 00:02:52.735813
2019-12-19 02:03:52.735813

模块之time与datetime的更多相关文章

  1. Python之日期与时间处理模块(date和datetime)

    本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常需要用到日期与时间,如: 作为日志信息的内容输出 计算某个功能的执行时 ...

  2. 【转】Python之日期与时间处理模块(date和datetime)

    [转]Python之日期与时间处理模块(date和datetime) 本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常 ...

  3. python标准模块(time、datetime及hashlib模块)

    一.time,datetime模块 时间相关的操作 import time time.sleep(5) # ==> 停顿多少秒 print(time.time()) # ==> 返回时间戳 ...

  4. python模块之time和datetime

    33.python模块之time      1.>>> time.time() 1470900847.8458395 ==>时间戳,从1970年到现在.      2.> ...

  5. Python 第五篇(上):算法、自定义模块、系统标准模块(time 、datetime 、random 、OS 、sys 、hashlib 、json和pickle)

    一:算法回顾: 冒泡算法,也叫冒泡排序,其特点如下: 1.比较相邻的元素.如果第一个比第二个大,就交换他们两个. 2.对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应 ...

  6. python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块

    正则表达式   语法:             mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...

  7. python常见模块之time,datetime模块

    一.time模块 time模块提供了一些用于管理时间和日期. time模块中时间的表现形式有三种: format_string  格式化的字符串 struct_time     结构化时间 times ...

  8. Python模块之time、datetime

    python内置模块系列(一):time模块与datetime time模块是python内置查看当前时间戳的一个模块 一 time 1 获得时间戳 时间戳:通常来说,时间戳表示的是从1970年1月1 ...

  9. day5模块学习 -- time、datetime时间模块

    1.定义 模块:用来从逻辑上组织python(变量,函数,类,逻辑:实现一个功能)代码,本质就是.py结尾的python文件(文件名:test.py,对应的模块名test) 包:用来从逻辑上组织模块的 ...

随机推荐

  1. Sql UpdateOrInsert

    SqlServer(先更新,受影响条数为0,则Insert,通过事务): begin tran update table set column=columnvalue where wherestr b ...

  2. python 类中__getattr__的使用

    class F: def __init__(self, name): self.name = name def __getattr__(self, item): return '__getattr__ ...

  3. java源码-CountDownLatch源码分析

    这次分析CountDownLatch,相信大部分人都用过把! CountDownLatch内部还是Sync对象,还是基础AQS(可见其重要性),首先看一下CountDownLatch初始化,Count ...

  4. IDEA工具上传项目报:Push rejected: Push to origin/master was rejected

    原文:https://blog.csdn.net/a137151062/article/details/78820806 解决方案如下: 1.切换到自己项目所在的目录,右键选择GIT BASH Her ...

  5. Using NodeLists

    Understanding a NodeList object and its relatives, NamedNodeMap and HTMLCollection, is critical to a ...

  6. tween.js的API实践

    看了网上多篇关于tween的使用教程,基本上千篇一律,大多数的写法都是像下面这样: function initTween(geometry) { }; tween = }, ); tween.easi ...

  7. JS apply 、call和bind

    JS当中的call .apply.和bind 这三个方法都是js function当中自带的方法,用来改变this的指向. call()方法 语法格式: fun.call(thisArg[,arg1[ ...

  8. 如何在VUE中使用leaflet地图框架

    前言:在leaflet的官方文档只有静态的HTML演示并没有结合VUE的demo  虽然也有一些封装好的leaflet库例如Vue-Leaflet,但是总感觉用起来不是那么顺手,有些业务操作还是得用l ...

  9. php使用装饰模式无侵入式加缓存

    <?php namespace App\Services; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\ ...

  10. 小程序onLaunch事件的坑

    记一个小程序踩过的坑 小程序项目中app.js里面定义了globalData,即全局变量,里面定义了一个token字段 需求是这样的,每次进入小程序的时候需要检验该token有没有,没有就请求后台获取 ...