python(5) - time模块
import time
1. time.gmtime() 显示当前structtime,格林时间
>>> import time
>>> time.gmtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=12, tm_min=48, tm_s
ec=25, tm_wday=6, tm_yday=73, tm_isdst=0)
>>> a = time.gmtime()
>>> print(a.tm_year)
2016
2. time.localtime() 显示当前本地时间,structime
>>> time.localtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=20, tm_min=51, tm_s
ec=35, tm_wday=6, tm_yday=73, tm_isdst=0)
3. time.time() 当前系统时间戳,以毫秒为单位的时间,从1970年到现在
>>> time.time()
1457873653.96087
4. time.strftime("%Y-%m-%d %H:%M:%S") 将strucktime格式化输出
>>> time.strftime("%Y-%m-%d %H:%M:%S")
'2016-03-13 20:58:49'
>>> time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
'2016-03-13 13:05:55'
5. time.mktime() 将strucktime变成时间戳
>>> time.mktime(time.localtime())
1457874273.0
>>>
6. time.strptime() 转换成strucktime格式
>>> time.strptime("2015-04-03", "%Y-%m-%d")
time.struct_time(tm_year=2015, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=
0, tm_wday=4, tm_yday=93, tm_isdst=-1)
7. time.ctime() 系统格式输出当前系统时间,也可用于将时间戳转换成系统格式
>>> time.ctime()
'Sun Mar 13 21:10:58 2016'
>>> time.ctime(1457874763.685563)
'Sun Mar 13 21:12:43 2016'
python(5) - time模块的更多相关文章
- python之platform模块
python之platform模块 ^_^第三个模块从天而降喽!! 函数列表 platform.system() 获取操作系统类型,windows.linux等 platform.platform() ...
- python之OS模块详解
python之OS模块详解 ^_^,步入第二个模块世界----->OS 常见函数列表 os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows ...
- python之sys模块详解
python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...
- 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)
一 安装,导入模块 安装: pip3 install 模块名称 导入: import module from module.xx.xx import xx from module.xx.xx impo ...
- linux下python调用c模块
在C调用Python模块时需要初始化Python解释器,导入模块等,但Python调用C模块却比较简单,下面还是以helloWorld.c 和 main.py 做一说明: (1)编写C代码,hel ...
- Python学习之模块进程函数详解
今天在看<Beginning Linux Programming>中的进程相关部分,讲到Linux几个进程相关的系统函数: system , exec , fork ,wait . Pyt ...
- python基础——第三方模块
python基础——第三方模块 在Python中,安装第三方模块,是通过包管理工具pip完成的. 如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了. 如果你正在使用Window ...
- python基础——使用模块
python基础——使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env ...
- python 中time模块使用
在开始之前,首先要说明这几点: 1.在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主 ...
- Python之logging模块
一.引言 之前在写一些小程序的时候想把日志内容打到文件中,所以就自己写了一个logger.py的程序,如下: #!/usr/bin/python # -*- coding=utf-8 -*- impo ...
随机推荐
- post和put的区别
post : 标识的是处理请求中资源表述的资源 put : 标识的是请求的资源表述 post : 支持多种类型的资源 put : 支持单一的资源
- DedeCMS Error:Tag disabled:"php"的解决办法
- HDU 5781 ATM Mechine (概率DP)
ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- #JAVA操作LDAP
package com.wisdombud.unicom.monitor.ldap; import java.util.ArrayList; import org.slf4j.Logger; impo ...
- internet访问局域网内部方法之----------路由器端口映射
很多人每天都问为什么要端口映射?例如:通过路由器上网的,网站自己可以访问,但是别人就不能:输入127.0.0.1可以访问,别人还是看不到:输入localhost可以看到,但是别人就是看不到,气人啊-没 ...
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- oracle ibatis 存储过程 返回游标 嵌套表
自己解决问题了 问题总结: 1.index by表不能存储在数据库中的type中,故选择嵌套表. 2.ibatis不支持oracle的复合数据类型的返回.(个人理解) 3.替代方案:用返回oracle ...
- ASP.NET MVC- 数据验证机制
ASP.NET MVC的数据验证机制,比起ASP.NET WEBFORM那种高效很多.下面记录以下两个示例,以便日后方便查阅. 方式一:在Controller里通过AddModelError方法返回错 ...
- C++多态实现(虚函数,成员函数覆盖、隐藏)
// 1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using namespace ...
- jqGrid 学习
jqGrid 学习: 一.下载需要的jqGrid包:http://www.trirand.com/blog/?page_id=6 二.下载JQuery UI:http://jqueryui.com/d ...