Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

python ×Ö·û´®ºÍdatetimeת»»

       ΪÁË´Ó×Ö·û´®ÖÐÌáȡʱ¼ä£¬²¢½øÐбȽϣ¬Òò´ËÓÐÁËÕâ¸öÎÊÌ⣬ÈçºÎ½«×Ö·û´®×ª»»³ÉdatetimeÀàÐÍ
       1.×Ö·û´®ÓëtimeÀàÐ͵Äת»»
>>> import time
>>> timestr = "time2009-12-14"
>>> t = time.strptime(timestr, "time%Y-%m-%d")
>>> print t
(2009, 12, 14, 0, 0, 0, 0, 348, -1)
>>> type(t)
<type 'time.struct_time'>
>>>
 
Èç´úÂëËùʾʹÓÃstrptime½øÐÐת»»£¬µÚÒ»¸ö²ÎÊýÊÇҪת»»µÄ×Ö·û´®£¬µÚ¶þ¸ö²ÎÊýÊÇ×Ö·û´®ÖÐʱ¼äµÄ¸ñʽ
 
ÓëÖ®¶ÔÓ¦µÄÓк¯Êýstrftime£¬Êǽ«timeÀàÐÍת»»ÏàÓ¦µÄ×Ö·û´®
 
ÏÂÃæÊǸñʽ»¯·ûºÅ»ã×Ü
¡¡¡¡%a ÐÇÆÚ¼¸µÄ¼òд Weekday name, abbr.
¡¡¡¡%A ÐÇÆÚ¼¸µÄÈ«³Æ Weekday name, full
¡¡¡¡%b Ô·ֵļòд Month name, abbr.
¡¡¡¡%B Ô·ݵÄÈ«³Æ Month name, full
¡¡¡¡%c ±ê×¼µÄÈÕÆÚµÄʱ¼ä´® Complete date and time representation
¡¡¡¡%d Ê®½øÖƱíʾµÄÿÔµĵڼ¸Ìì Day of the month
¡¡¡¡%H 24СʱÖƵÄСʱ Hour (24-hour clock)
¡¡¡¡%I 12СʱÖƵÄСʱ Hour (12-hour clock)
¡¡¡¡%j Ê®½øÖƱíʾµÄÿÄêµÄµÚ¼¸Ìì Day of the year
¡¡¡¡%m Ê®½øÖƱíʾµÄÔÂ·Ý Month number
¡¡¡¡%M ʮʱÖƱíʾµÄ·ÖÖÓÊý Minute number
¡¡¡¡%S Ê®½øÖƵÄÃëÊý Second number
¡¡¡¡%U µÚÄêµÄµÚ¼¸ÖÜ£¬°ÑÐÇÆÚÈÕ×öΪµÚÒ»Ì죨ֵ´Ó0µ½53£©Week number (Sunday first weekday)
¡¡¡¡%w Ê®½øÖƱíʾµÄÐÇÆÚ¼¸£¨Öµ´Ó0µ½6£¬ÐÇÆÚÌìΪ0£©weekday number
¡¡¡¡%W ÿÄêµÄµÚ¼¸ÖÜ£¬°ÑÐÇÆÚÒ»×öΪµÚÒ»Ì죨ֵ´Ó0µ½53£© Week number (Monday first weekday)
¡¡¡¡%x ±ê×¼µÄÈÕÆÚ´® Complete date representation (e.g. 13/01/08)
¡¡¡¡%X ±ê×¼µÄʱ¼ä´® Complete time representation (e.g. 17:02:10)
¡¡¡¡%y ²»´øÊÀ¼ÍµÄÊ®½øÖÆÄê·Ý£¨Öµ´Ó0µ½99£©Year number within century
¡¡¡¡%Y ´øÊÀ¼Í²¿·ÖµÄÊ®ÖÆÄê·Ý Year number
¡¡¡¡%z£¬%Z ʱÇøÃû³Æ£¬Èç¹û²»Äܵõ½Ê±ÇøÃû³ÆÔò·µ»Ø¿Õ×Ö·û¡£Name of time zone
¡¡¡¡%% °Ù·ÖºÅ
 
 
2.timeÀàÐÍÓëdatetimeÀàÐ͵Äת»»
 
ÕâÒ»²½±È½Ï¼òµ¥£¬Ê¹ÓÃdatetimeº¯Êý£¬´úÂëÈçÏÂ
>>> import datetime
>>> d = datetime.datetime(* t[:6])
>>> print d
2009-12-14 00:00:00
>>> type(d)
<type 'datetim


Ïà¹ØÎĵµ£º

Python ×Ö·û´®·½·¨Ïê½â


ÀàÐÍ
·½·¨
×¢½â
Ìî³ä
center(width[, fillchar]) ,
ljust(width[, fillchar]),
rjust(width[, fillchar]),
zfill(width),
expandtabs([tabsize])
l        
fillchar ²ÎÊýÖ¸¶¨ÁËÓÃÒÔÌî³äµÄ×Ö·û£¬Ä¬ÈÏΪ¿Õ¸ñ
l        
¹Ë ......

Python×Ö·û´®µÄencodeÓëdecode


Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö·û´®×ª» ......

python ·ÖÐÎ


´úÂëÈçÏ£º
#!/usr/bin/env python
# -*-coding:UTF-8-*-#
from common import *
import Image, ImageFilter, math, sys, os, random
def modifyImageObj(img, matrix) :
    width, height = img.size   
   
    for h in range(0, height) :&n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ