易截截图软件、单文件、免安装、纯绿色、仅160KB

python time 字符串转UTC

今天遇到一个一个问题,是将字符串类型的时间转化为UTC时间。例如time_str = "2009/11/09 12:23:23" 转化为UTC int型。
找了一些资料,发现time模块就能完成这个转换。
import time
time_str = "2009/11/09 12:23:23"
time_s = time.strptime(time_str,"%Y/%m/%d %H:%M:%S")
utc_f = time.mktime(time_s)
utc_i = int(time.mktime(time_s))
print time_s
(2009, 11, 9, 12, 23, 23, 0, 313, -1)
print utc_f
1257740603.0
print utc_t
1257740603

在linux中输入“date  +%s” 就能输出当前utc时间。
附录:
http://www.opengroup.org/onlinepubs/009695399/functions/strptime.html
Directive:
%a - abbreviated weekday name
%A - full weekday name
%b - abbreviated month name
%B - full month name
%c - preferred date and time representation
%C - century number (the year divided by 100, range 00 to 99)
%d - day of the month (01 to 31)
%D - same as %m/%d/%y
%e - day of the month (1 to 31)
%g - like %G, but without the century
%G - 4-digit year corresponding to the ISO week number (see %V).
%h - same as %b
%H - hour, using a 24-hour clock (00 to 23)
%I - hour, using a 12-hour clock (01 to 12)
%j - day of the year (001 to 366)
%m - month (01 to 12)
%M - minute
%n - newline character
%p - either am or pm according to the given time value
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a number (1 to 7), Monday=1. Warning: In Sun Solaris Sunday=1
%U - week number of the current year, starting with the first Sunday as the first day of the first week
%V - The ISO 8601 week number of the current year (01 to 53), where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week
%W - week number of the current year, starting with the first Monday as the first day of the first week
%w - day of the week as a decimal, Sunday=0
%x - preferred date representation without the time
%X -


相关文档:

python如何连接MySQL数据库

 
#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE  : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#================ ......

一个大牛整理的python资源

 Python基本安装:
    * http://www.python.org/ 官方标准Python开发包和支持环境,同时也是Python的官方网站;
    * http://www.activestate.com/ 集成多个有用插件的强大非官方版本,特别是针对Windows环境有不少改进;
Python文档:
    * http://www.pyth ......

Python 之禅

import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough t ......

python 好东东

ipython 如果没有用装, 那就赶紧装上, 这个东西比起python自己带的那个交互界面要好用很多
shutil 类似于shell的一些接口, 比如 cp, mv等等
subprocess 调用子进程
optparse 解析命令行参数的, 用它来应付命令行参数, 简洁, 清晰
sqlite3 数据库, 进程级的数据库, 很酷, 甚至可以把这个数据库建在内存里. http://www.py ......

学习《Python语言入门》第十章框架与应用

关于框架,之前听得比较多,特别是在CPyG的邮件列表上,不过还没有接触过。
这一章我打算略读,加上这两天身体不适,读得更加略了。
这一章提到的几个框架我听说的有TKinter和SWIG。SWIG搞了一下,TKinter看人家用过,自己还没有用过。对这些框架陌生得很。以后碰上要用了再认真学学。
到现在,对Python算是有些了解了。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号