python之time模块详解_python time模块详解

python time模块详解

python 的内嵌time模板翻译及说明

一、简介

time模块提供各种操作时间的函数

说明:一般有两种表示时间的方式:

第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的

第二种以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同

year (four digits, e.g. 1998)

month (1-12)

day (1-31)

hours (0-23)

minutes (0-59)

seconds (0-59)

weekday (0-6, Monday is 0)

Julian day (day in the year, 1-366)

DST (Daylight Savings Time) flag (-1, 0 or 1) 是否是夏令时

If the DST flag is 0, the time is given in the regular time zone;

if it is 1, the time is given in the DST time zone;

if it is -1, mktime() should guess based on the date and time.

夏令时介绍:http://baike.baidu.com/view/100246.htm

UTC介绍:http://wenda.tianya.cn/wenda/thread?tid=283921a9da7c5aef&clk=wttpcts

二、函数介绍

1.asctime()

asctime([tuple]) -> string

将一个struct_time(默认为当时时间),转换成字符串

Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.

When the time tuple is not present, current time as returned by localtime()

is used.

2.clock()

clock() -> floating point number

该函数有两个功能,

在第一次调用的时候,返回的是程序运行的实际时间;

以第二次之后的调用,返回的是自第一次调用后,到这次调用的时间间隔

示例:

import time

if __name__ == '__main__':

time.sleep(1)

print "clock

相关文档:

参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html

一 动态导入模块

Python的import不能接受变量,所以应该用 __import__函数来动态导入。

如下的代码无法正常导入模块

modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......

初学python,现在要读一个二进制文件,查找doc只发现file提供了一个read和write函数,而且读写的都是字符串,如果只是读写char等一个字节的还行,要想读写如int,double等多字节数据就不方便了。在网上查到一篇贴子,使用struct模块里面的pack和unpack函数进行读写。下面就自己写代码验证一下。

>>> from struct ......

既然选择了远方,就必须日夜兼程 http://wrsuifeng.javaeye.com

Python代码

# Filename: excel.py

import os,sys,time

import win32com.client

import traceback

excel = win32com.client.Dispatch(" ......

http://www.cnblogs.com/Jedimaster/archive/2007/02/28/660209.html

朋友的家人做生意,每日从各地分店处收集报表,然后回去汇总。由于不想用那种复杂的管理软件,就叫他写一个小工具。于是他找到了我,让我想想办法。

Python是个令人惊奇的工具,而不仅仅是一种语言。对比老牌的Perl,看似Python不是那么的精通 ......

CSDN站内转帖:

http://blog.csdn.net/kiki113/archive/2009/03/28/4033017.aspx

python 的内嵌time模板翻译及说明

一、简介

time模块提供各种操作时间的函数

说明:一般有两种表示时间的方式:

第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒� ......


版权声明:本文为weixin_35702787原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。