python畫出來的電子時鐘

來源:互聯網
上載者:User

先看(windows下):

在IDLE下沒有重新整理顯示的功能:

畫數位時候是一行一行畫出來的,很幸苦。

注釋沒用中文,因為在windows cmd下運行會出錯,IDLE下無所謂

獲得時間:

time.strftime('%Y-%m-%d',time.localtime(time.time()))

其中的格式有下列:

%y 兩位元的年份表示(00-99)
%Y 四位元的年份表示(000-9999)
%m 月份(01-12)
%d 月內中的一天(0-31)
%H 24小時制小時數(0-23)
%I 12小時制小時數(01-12) 
%M 分鐘數(00=59)
%S 秒(00-59)

%a 本地簡化星期名稱
%A 本地完整星期名稱
%b 本地簡化的月份名稱
%B 本地完整的月份名稱
%c 本地相應的日期表示和時間表示
%j 年內的一天(001-366)
%p 本地A.M.或P.M.的等價符
%U 一年中的星期數(00-53)星期天為星期的開始
%w 星期(0-6),星期天為星期的開始
%W 一年中的星期數(00-53)星期一為星期的開始
%x 本地相應的日期表示
%X 本地相應的時間表示
%Z 當前時區的名稱


代碼(python2.5.4):

import timeimport os#print the num(0-9)def printline(line,num):    if line==1:        if num==1:            print '   # ',        if num==0 or num==2 or num==3 or num==5 or num==6 or num==7 or num==8 or num==9:            print '#### ',        if num==4:            print '#  # ',    if line==2:        if num==1:            print '   # ',        if num==2 or num==3 or num==7:            print '   # ',        if num==4 or num==8 or num==9 or num==0:            print '#  # ',        if num==5 or num==6:            print '#    ',    if line==3:        if num==1:            print '   # ',        if num==2 or num==3 or num==4 or num==5 or num==6 or num==8 or num==9:            print '#### ',        if num==7:            print '   # ',        if num==0:            print '#  # ',    if line==4:        if num==1:            print '   # ',        if num==2:            print '#    ',        if num==3 or num==4 or num==5 or num==7 or num==9:            print '   # ',        if num==6 or num==8 or num==0:            print '#  # ',    if line==5:        if num==1:            print '   # ',        if num==2 or num==3 or num==5 or num==6 or num==8 or num==9 or num==0:            print '#### ',        if num==4 or num==7:            print '   # ',#print the timedef printtime(hour,minute,second):    h=int(hour)    m=int(minute)    s=int(second)    hn=divmod(h,10)    mn=divmod(m,10)    sn=divmod(s,10)    #print hn        for i in range(1,6):        printline(i,hn[0])        printline(i,hn[1])        if i==2 or i==4:            print ' # ',        else:            print '   ',                    printline(i,mn[0])        printline(i,mn[1])        if i==2 or i==4:            print ' # ',        else:            print '   ',                    printline(i,sn[0])        printline(i,sn[1])        print ''        #get the local System times=time.strftime('%S',time.localtime(time.time()))jiange=int(raw_input("input the refresh time(second):"))while True:    hour=time.strftime('%H',time.localtime(time.time()))    minute=time.strftime('%M',time.localtime(time.time()))    second=time.strftime('%S',time.localtime(time.time()))    #print hour+":"+minute+":"+second        if int(second)-int(s)>=jiange:        os.system("cls")        printtime(hour,minute,second)        print '\n\n'        s=time.strftime('%S',time.localtime(time.time()))    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.