#!/usr/bin/env python
# -*- coding: utf-8 -*- import time print(time.clock())##返回处理器时间,3.3开始已废弃 , 改成了time.process_time()测量处理器运算时间,不包括sleep时间,不稳定,mac上测不出来
print(time.process_time())
print(time.altzone)#返回与utc时间的时间差,以秒计算\
print(time.asctime())#返回时间格式“Thu Nov 3 10:04:39 2016”
print(time.localtime())#返回本地时间的struct time 对象格式
print(time.gmtime(time.time()-800000))#返回utc时间的struc时间对象格式 print(time.asctime(time.localtime()))#返回时间格式“Thu Nov 3 10:07:36 2016”
print(time.ctime())#返回Thu Nov 3 10:08:41 2016 #日期字符串转成 时间戳
string_2_struct = time.strptime("2016/05/22","%Y/%m/%d")#将日期字符串转成 struct时间对象格式
print(string_2_struct)
#
struct_2_stamp = time.mktime(string_2_struct)#将struct时间对象转成时间戳
print(struct_2_stamp) #将时间戳转为字符串格式
print(time.gmtime(time.time()-86640))#将utc时间戳转换成struct_time格式
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()))#将utc struct_time格式转成指定的字符串格式 #时间加减
import datetime print(datetime.datetime.now())#返回 2016-11-03 10:51:04.385070
print(datetime.date.fromtimestamp(time.time()))#时间戳直接转成日期格式 2016-11-03
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=3))#当前时间+3分钟 #
c_time = datetime.datetime.now()
print(c_time.replace(minute=3,hour=2)) #时间替换
Directive Meaning Notes
%a Locale’s abbreviated weekday name.  
%A Locale’s full weekday name.  
%b Locale’s abbreviated month name.  
%B Locale’s full month name.  
%c Locale’s appropriate date and time representation.  
%d Day of the month as a decimal number [01,31].  
%H Hour (24-hour clock) as a decimal number [00,23].  
%I Hour (12-hour clock) as a decimal number [01,12].  
%j Day of the year as a decimal number [001,366].  
%m Month as a decimal number [01,12].  
%M Minute as a decimal number [00,59].  
%p Locale’s equivalent of either AM or PM. (1)
%S Second as a decimal number [00,61]. (2)
%U Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. (3)
%w Weekday as a decimal number [0(Sunday),6].  
%W Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. (3)
%x Locale’s appropriate date representation.  
%X Locale’s appropriate time representation.  
%y Year without century as a decimal number [00,99].  
%Y Year with century as a decimal number.  
%z Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59].  
%Z Time zone name (no characters if no time zone exists).  
%% A literal '%' character.

python杂记-6(time&datetime模块)的更多相关文章

  1. Python的time和datetime模块

    Python的time和datetime模块 time 常用的有time.time()和time.sleep()函数. import time print(time.time()) 149930555 ...

  2. python中time、datetime模块的使用

    目录 python中time.datetime模块的使用 1.前言 2.time模块 1.时间格式转换图 2.常用方法 3.datetime模块 python中time.datetime模块的使用 1 ...

  3. Python 入门之 内置模块 -- datetime模块

    Python 入门之 内置模块 -- datetime模块 1.datetime模块 from datetime import datetime (1)datetime.now() 获取当前时间和日期 ...

  4. Python中time和datetime模块的简单用法

    python中与时间相关的一个模块是time模块,datetime模块可以看为是time模块的高级封装. time模块中经常用到的有一下几个方法: time()用来获取时间戳,表示的结果为从1970年 ...

  5. python基础--time和datetime模块

    一:说明在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平台可能 ...

  6. [ Python入门教程 ] Python中日期时间datetime模块使用实例

    Python中datetime模块提供强大易用的日期处理功能,用于记录程序操作或修改时间.时间计算.日志时间显示等功能.datatime模块重新封装了time模块,提供的类包括date.time.da ...

  7. python标准库:datetime模块

    原文地址:http://www.bugingcode.com/blog/python_datetime.html datatime 模块题共用一些处理日期,时间和时间间隔的函数.这个模块使用面向对象的 ...

  8. Python之 time 与 datetime模块

    time与datetime模块 一.time 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏 ...

  9. 【Python】Python的time和datetime模块

    time 常用的有time.time()和time.sleep()函数. import time print(time.time()) 1499305554.3239055 上面的浮点数称为UNIX纪 ...

随机推荐

  1. MVC框架 - 异常处理

    在ASP.NET中,错误处理是通过使用标准的尝试捕捉方法或使用应用程序事件.ASP.NET MVC附带内置支持,被称为异常过滤器功能异常处理.在这里我们要学习两种方法:一个是定义HandleError ...

  2. linux服务监控脚本

    配置需要监控的服务器 数组定义:host_ports=(host_name=host_port=uri_path)host_name为容易识别的服务器名称host_port为服务器ip和服务端口uri ...

  3. JavaScript 键盘event.keyCode值列表大全

      JavaScript 键盘event.keyCode值列表大全   event.keyCode值列表大全,对于需要根据键盘按键触发相应事件的朋友需要. 网上收集的KeyCode值方便大家查找: k ...

  4. ShowModal在FireMonkey移动应用程序对话框

    This is the only code that changes between the first and second code snippets: dlg.ShowModal(procedu ...

  5. 51nod 数数字(水题)

    题目链接: 数数字 基准时间限制:1 秒 空间限制:262144 KB 统计一下 aaa ⋯ aaa n个a × b 的结果里面有多少个数字d,a,b,d均为一位数. 样例解释: 3333333333 ...

  6. 理论制作 Windows 开机动画

    第一次接触 Windows 开机动画是 2012 年,那时候魔方的版本号还是 3.12,魔方里面有个很酷炫狂霸拽的功能就是替换 Windows 7 的开机动画.一开始我是在IT之家论坛里下载开机动画, ...

  7. oracle 常用技巧及脚本

    [Q]怎么样查询特殊字符,如通配符%与_ [A]select * from table where name like 'A/_%' escape '/' [Q]如何插入单引号到数据库表中 [A]可以 ...

  8. link_mysql的php版

    <?php $str_sql_read="select count(*) as num from userinfo"; $str_sql_del="delete f ...

  9. asp结合ajax中文乱码问题

    XMLHttpRequest 在w3c标准中这样提到: 如果响应包含了为响应体指定字符编码的头部,就使用该编码.否则,假定使用 Unicode UTF-8. 前端页面sele.asp <&quo ...

  10. Javascript获取URL地址变量参数值的方法

    今天碰到在做一个动态页面的时候,需要用到 URL 的参数值来作判断,从而决定某一块内容在当前页面是否显示.例如exampe.html?parm1=xxx&parm2=xxx&parm3 ...