python的time模块
#encoding=utf-8
import time # 返回时间戳
print time.time() # 延迟运行单位为s,如下为延迟3s
time.sleep(3) # 转换时间戳为时间元组(时间对象),自1970+second,其second为秒数
print time.gmtime(4) # 转换时间戳为本地对象
print time.localtime() # 将时间戳转换为字符串
print time.asctime(time.localtime()) # 将时间戳转换为字符串
print time.ctime(5) # 将本地时间转换为时间戳
t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
print time.mktime(t) # 将时间对象转换为规范性字符串(常用),格式如下
'''
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%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.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
'''
print time.strftime('%Y-%m-%d %H-%M-%S',t) # 将时间字符串根据指定的格式化符转换成数组形式的时间
struct_time = time.strptime("30 Nov 00", "%d %b %y")
print struct_time
python的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 ...
随机推荐
- leetcode-algorithms-24 Swap Nodes in Pairs
leetcode-algorithms-24 Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and re ...
- 转-【exp/imp】将US7ASCII字符集的dmp文件导入到ZHS16GBK字符集的数据库中
原帖地址:http://blog.csdn.net/lihuarongaini/article/details/71512116 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者,看完 ...
- 函数使用十二:BAPI_MATERIAL_BOM_GROUP_CREATE(CS61)
REPORT ZSM_CREATE_SIMPLEBOM.* This code will create a material BoM for the material* MAINMATERIAL wi ...
- java调用url
1 try { String str; URL u = new URL("https://www.baidu.com"); InputStream is = u.openStrea ...
- mysqldump导出报错"mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `file_storage` at row: 29"
今天mysql备份的crontab自动运行的时候,出现了报警,报警内容如下 mysqldump: Error 2013: Lost connection to MySQL server during ...
- SQLserver如何创建一个表
例如: create table news(news_id int primary key identity(1,1),news_title varchar(50) not null,news_aut ...
- 使用spring-cloud-starter-bus-amqp做微服务配置刷广播,config-client配置 未刷新的 问题
在需要配置刷新的(类或方法)上 加上 @RefreshScope 扩展:spring cloud:config-server中@RefreshScope的"陷阱"
- was控制台误禁用后的恢复启用办法
websphere是可以配置禁用控制台的,下面以was6.1.单profile.https控制台为例介绍在(误)禁用控制台后如何恢复启用控制台. 1. 禁用控制台 WCInboundAdmin--控制 ...
- MySQL升级教程(CentOS)
1.支持的升级方式 原地升级(In-Place Upgrade):直接替换二进制文件(即直接yum update/rpm -Uvh升级rpm包)数据库目录等都不变. 逻辑升级(Logical Upgr ...
- rexec/rlogin/rsh介绍
服务 是否需要密码 是否明文 功能 端口 rexec 是 是 远程执行命令 512 rlogin 是 是 远程登录得到shell 513 rsh 是 是 可远程执行命令,也可远程登录得到shell 5 ...