python datetime 模块
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 模块的更多相关文章
- python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客
python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客 python datetime模块strptime/strptime form ...
- python datetime模块参数详解
Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块,它提供 的接口与C标准库time.h基本一致.相比于time模块,datetime模块的接 ...
- Python datetime模块的介绍
datetime模块常用的主要有下面这四个类:(要清楚import datetime : 导入的是datetime这个包,包里有各种类) 1. datetime.date 用于表示年月日构成的日期 ...
- python——datetime模块
一.datetime模块介绍 (一).datetime模块中包含如下类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间对象 datetime 日期时 ...
- Python datetime模块的datetime类
datetime模块定义了下面这几个类: datetime.date:表示日期的类.常用的属性有year, month, day. datetime.time:表示时间的类.常用的属性有hour, m ...
- python datetime模块详解
datetime是python当中比较常用的时间模块,用于获取时间,时间类型之间转化等,下文介绍两个实用类. 一.datetime.datetime类: datetime.datetime.now() ...
- python datetime模块
该模块的时间有限时限:1 - 9999 dir(datetime) from datetime import datetime, timedelta, timezone dt = datetime. ...
- python datetime模块用strftime 格式化时间
1 2 3 #!usr/bin/python import datetime datetime.datetime.now() 这个会返回 microsecond.因此这个是我们不需要的.所以得做一下修 ...
- python datetime模块来获取当前的日期和时间
#!/usr/bin/python # -*- coding: UTF- -*- import datetime i = datetime.datetime.now() print ("当前 ...
- python datetime模块用法
1. 创建naive(无时区信息)的datetime对象 import datetime dt_utc = datetime.datetime.utcnow() dt_utc # datetime.d ...
随机推荐
- laravel数据库配置
1.说明,查看laravel数据库配置 项目名/config/database.php 'default' => env('DB_CONNECTION', 'mysql') 2.数据开发 ...
- js 六种数据类型的区别及bool 转换判断
一.bool型转换判断: 1.true 和 1 比较是相同,false 和 0 比较是相同(是 “==” 比较),因为内部会实现数据类型的 转化,将true 转换成1,将false 转换成0, js ...
- [Laravel] 11 - WEB API : cache & timer
前言 一.资源 Ref: https://www.imooc.com/video/2870 二.缓存 缓存:静态缓存.Memcache.redis缓存 Ref: [Laravel] 09 - Func ...
- 8 -- 深入使用Spring -- 6... Spring的事务
8.6 Spring 的事务 8.6.1 Spring支持的事务策略 8.6.2 使用XML Schema配置事务策略 8.6.3 使用@Transactional 参考1. 啦啦啦 我早就肯定我的身 ...
- JavaScript 之 function函数及参数arguments
JavaScript用function关键字声明函数,可以用return返回值,也可以没有返回值. 建议:要么统一有返回值,要么统一都没有返回值,这样调试代码方便. 函数定义格式: function ...
- web站点健康检测和告警小脚本
#!/bin/sh web01="http://172.18.52.xx:8080/web/api/getTime" web02="http://172.18.52.xx ...
- Python 字典 fromkeys()方法
Python 字典 fromkeys() 方法用于创建一个新的字典,并以可迭代对象中的元素分别作为字典中的键,且所有键对应同一个值,默认为None. fromkeys() 方法语法: 1 dict.f ...
- 7.11登入表单html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- D - Equation Again
This problem's author is too lazy to write the problem description, so he only give you a equation l ...
- io流和序列化
1.使用File操作文件 public class IoTest { public static void main(String[] args) throws IOException { /* 01 ...