#!/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. OC之Copy语法

    转载请注明:http://www.cnblogs.com/letougaozao/p/3631105.html 概念 内存管理 NSString的copy实例 对象的copy实例 一.概念 目的:在改 ...

  2. 重构6-Push Down Field(字段下移)

    与上移字段相反的重构是下移字段.同样,这也是一个无需多言的简单重构. public abstract class Task { protected String _resolution; } publ ...

  3. 监控服务器JVM内存运行

    使用jdk的jconsole进行监控jmx 首先,设置监控对象的端口   配置 catalina.sh #vi /usr/tomcat/bin/catalina.sh 注: /usr/tomcat/b ...

  4. ZOJ 1586 QS Network (最小生成树)

    QS Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Sta ...

  5. zoj 3057 博弈

    思路:对于TT来说,如果数量分别为a a b或 a b a,或 b a a的形式,那么TT必赢,因为TT可以使其成为 a a a的形式,那么不论DD 怎么拿,都是TT最后使其成为a a a 的形式,0 ...

  6. GSS1 spoj 1043 Can you answer these queries I 最大子段和

    今天下午不知道要做什么,那就把gss系列的线段树刷一下吧. Can you answer these queries I 题目:给出一个数列,询问区间[l,r]的最大子段和 分析: 线段树简单区间操作 ...

  7. ASP.NET不拖控件教程(1)-认识JSON

    我讲讲脱离ASP.NET控件必备的一步,JSON和使用JQuery获取JSON吧! 高手跳过,写给学习中的人的.这篇帖子是假设你会使用JQuery(JQ这么普及,应该不至少没学过吧!真没学过以后再开帖 ...

  8. Java之姐妹素数

    所谓素数就是指相邻两个奇数均为素数, 判断一个数是否为素数的基本方法是:(以n=5为例) package com.cdp.SuShu; public class sushujisuan { publi ...

  9. webkit常见问题汇总

    前段时间有人问我一个简单的问题,html如何创建解析的? 我讲了一大堆,什么通过DocumentLoader, CachedResourceLoader, CacheResource, Resourc ...

  10. 第九篇、自定义底部UITabBar

    国际惯例先上图: 代码实现(在UITabBarViewController设置): - (void)setUpTabBar { LHLTabBar *tabBar = [[LHLTabBar allo ...