import datetime

datetime.datetime.now()  打印本地当前时间
>>> print(datetime.datetime.now())
2017-12-20 17:30:31.035954
时间戳直接转成日期格式
>>> print(datetime.date.fromtimestamp(time.time()))
2017-12-20
把当前时间以指定的日期格式打印出来
>>> print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
2017-12-20 17:33:44

datetime.timedelta()  时间加减
显示当前时间+3天时间
print(datetime.datetime.now() + datetime.timedelta(days=3))

2017-12-24 10:53:23.549693

显示当前时间 -3天时间

print(datetime.datetime.now() + datetime.timedelta(days=-3))

2017-12-18 10:53:23.549693
当前时间+3小时
print(datetime.datetime.now() + datetime.timedelta(hours=3))

2017-12-21 13:53:23.549693
当前时间+30分钟
print(datetime.datetime.now() + datetime.timedelta(minutes=30))

2017-12-21 11:23:23.549693
自定义时间
c_time = (datetime.datetime.now())
print(c_time.replace(year=2016,month=3,day=5,hour=5,minute=5,second=40)) 2016-03-05 05:05:40.549693

 
 

 
 

python datetime 模块的更多相关文章

  1. python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客

    python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客     python datetime模块strptime/strptime form ...

  2. python datetime模块参数详解

    Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块,它提供 的接口与C标准库time.h基本一致.相比于time模块,datetime模块的接 ...

  3. Python datetime模块的介绍

    datetime模块常用的主要有下面这四个类:(要清楚import datetime : 导入的是datetime这个包,包里有各种类) 1. datetime.date   用于表示年月日构成的日期 ...

  4. python——datetime模块

    一.datetime模块介绍 (一).datetime模块中包含如下类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间对象 datetime 日期时 ...

  5. Python datetime模块的datetime类

    datetime模块定义了下面这几个类: datetime.date:表示日期的类.常用的属性有year, month, day. datetime.time:表示时间的类.常用的属性有hour, m ...

  6. python datetime模块详解

    datetime是python当中比较常用的时间模块,用于获取时间,时间类型之间转化等,下文介绍两个实用类. 一.datetime.datetime类: datetime.datetime.now() ...

  7. python datetime模块

    该模块的时间有限时限:1 - 9999 dir(datetime)  from datetime import datetime, timedelta, timezone dt = datetime. ...

  8. python datetime模块用strftime 格式化时间

    1 2 3 #!usr/bin/python import datetime datetime.datetime.now() 这个会返回 microsecond.因此这个是我们不需要的.所以得做一下修 ...

  9. python datetime模块来获取当前的日期和时间

    #!/usr/bin/python # -*- coding: UTF- -*- import datetime i = datetime.datetime.now() print ("当前 ...

  10. python datetime模块用法

    1. 创建naive(无时区信息)的datetime对象 import datetime dt_utc = datetime.datetime.utcnow() dt_utc # datetime.d ...

随机推荐

  1. Kubernetes集群部署之二CA证书制作

    创建TLS证书和秘钥 kubernetes 系统的各组件需要使用 TLS 证书对通信进行加密,本文档使用 CloudFlare 的 PKI 工具集 cfssl 来生成 Certificate Auth ...

  2. OSG描边特效osgFX::Outline的修改

    对一个三维场景中的物体实现描边特效,可以参考osg范例osgoutline 这个描边特效使用了模板缓存Stencil来实现,参见源代码osgFX/Outline.cpp 使用了两个Pass 第一个Pa ...

  3. autolayout 高度自适应

    https://lvwenhan.com/ios/449.html #import "ViewController.h" #import "MyTableViewCell ...

  4. Spark2 Random Forests 随机森林

    随机森林是决策树的集合. 随机森林结合许多决策树,以减少过度拟合的风险. spark.ml实现支持随机森林,使用连续和分类特征,做二分类和多分类以及回归. 导入包 import org.apache. ...

  5. Zookeeper中Session Timeout的那些事

    前言: RDS系统致力于MySQL数据的高可用,高可靠,高性能以及在线扩展功能,实现这些特性的主要逻辑功能都运行在管理服务器上,一旦管理服务器宕机,数据库的在线扩展功能/备份功能/故障恢复功能等都无从 ...

  6. Spark RDD Action 简单用例(二)

    foreach(f: T => Unit) 对RDD的所有元素应用f函数进行处理,f无返回值./** * Applies a function f to all elements of this ...

  7. 正则表达式、re模块

    正则表达式 一说规则我已经知道你很晕了,现在就让我们先来看一些实际的应用.在线测试工具 http://tool.chinaz.com/regex/ 正则表达式是用来匹配字符串非常强大的工具,在其他编程 ...

  8. CentOS 7.4下使用yum安装MySQL5.7.20 最简单的 (引用)

    引用 https://blog.csdn.net/z13615480737/article/details/78906598 CentOS7默认数据库是mariadb, 但是 好多用的都是mysql ...

  9. 项目()已配置为使用IIS Web服务器,但此计算机上...

    问题:x 就是要将一个项目,配置在IIS上,以前没遇上过这种开发模式啊... 解决方案: 0.如果配置为不使用IIS Web服务器,将Project.csproj中的" <UseIIS ...

  10. 阿里云VPC服务器通过ClassicLink访问经典网络服务器

    VPC中的服务器名称是 vpc-ecs1 , 经典网络中的服务器名称是 classic-ecs2 ,要实现 vpc-ecs1 通过内网访问 classic-ecs2 . VPC 网段是 10.0.0. ...