def calendar_(): cal = calendar.month(2017, 6) # by default w=2 l=1 print cal # 2017年6月份日历 print '--------------------' # calendar内置函数 #calendar of year 2017: c=distance(month); l=line(week); w=distance(day) print calendar.calendar(2017, w=2, l=1, c=6) #lenth(line)= 21* W+18+2* C print calendar.firstweekday() # start weekday, 0 by default, i.e. Monday # calendar.setfirstweekday(weekday) # 0(Monday) to 6(Sunday) print calendar.isleap(2017) # return True or False print calendar.leapdays(2000, 2016) # number of leap years between year 1 and year 2 print calendar.month(2017, 6) print calendar.monthcalendar(2017, 6) print calendar.monthrange(2017, 6) # return (a, b) a=starting weekday b=days in month calendar.prcal(2017, w=2, l=1, c=4) # equals to print calendar.calendar(2017, w=2, l=1, c=4) calendar.prmonth(2017, 6) # equals to print calendar.month(2017, 6) print calendar.timegm(time.localtime()) #和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍 print calendar.weekday(2017, 6, 30) # calendar.weekday(year,month,day) return date code
def test_output(self): self.assertEqual( self.normalize_calendar(calendar.calendar(2004)), self.normalize_calendar(result_2004_text) ) self.assertEqual( self.normalize_calendar(calendar.calendar(0)), self.normalize_calendar(result_0_text) )
def main(): ticks=time.time() print "当前时间戳为:", ticks localtime=time.asctime(time.localtime(time.time())) print "localtime=", localtime print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) a = "Sat Mar 28 22:24:24 2016" print time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")) cal=calendar.month(2017,7) print "日历" print cal print calendar.calendar(2015,w=2,l=1,c=6)
def calendar(): import calendar#引入calender #获取某月日历 cal=calendar.month(2017,1) print '以下输出2017年1月的日历 ' print cal #判断是否为闰年 print calendar.isleap(2016) print calendar.isleap(2017) #获取某年日历 print calendar.calendar(2017,w=2,l=1,c=6)
def onHome(self, year=None): if year: result = calendar.calendar(int(year)) else: result = "" self.writeOKHeaders('text/html') self.write(self._form % result)
def render(self, request): return """<html> <body> <pre> %s </pre> </body> </html>"""%(calendar(self.year),)
def calTab(): print("calclicked") toplevel=Toplevel() toplevel.title('Calendar') toplevel.focus_set() toplevel.geometry("700x500") yrcal = calendar.calendar(2016, 2,1,10) yrCalOut = Label(toplevel, text = yrcal, font=('courier', 12, 'bold'), bg='#ffffff') yrCalOut.pack()
def calendar(): import calendar #Entire Calendar #calendar.calendar(year,w,l,c) #w = width between characters #l = number of lines for each week #c column spacing cal = calendar.calendar(2014,2,1,6) print cal
def calendar_right_bottom(request,page_owner,Task): """ this is used to get the details of the users tasks,subtasks in calendar format , will be displayed on the right bottom of pages """ now = datetime.datetime.now() today=now.day year=now.year month=now.month month_arr=["Jan" ,"Feb" ,"Mar" ,"April" ,"May" ,"Jun" ,"Jul" ,"Aug" ,"Sept","Oct","Nov","Dec"] month_name=month_arr[month-3:month+2] #the calander object mycalendar_b2 = calendar.monthcalendar(year ,month-1) mycalendar_b1= calendar.monthcalendar(year ,month-2) mycalendar = calendar.monthcalendar(year ,month) mycalendar_year = calendar.calendar(year) mycalendar_f1 = calendar.monthcalendar(year ,month+1) if(month ==11): mycalendar_f2 = calendar.monthcalendar(year+1 ,1) else: mycalendar_f2 = calendar.monthcalendar(year ,month+2) if is_core(page_owner): user_tasks=Task.objects.filter(creator = page_owner) else: user_tasks=SubTask.objects.filter(coords=page_owner) first_week_day=weekday(mycalendar[0])#gives the gap between weekday number of 1st calendar_data_b2=[[{'subtask':[],'date':0} for x in range(0,7)]for y in range(0,6)] calendar_data_b1=[[{'subtask':[],'date':0} for x in range(0,7)]for y in range(0,6)] calendar_data=[[[{'subtask':[],'date':0} for x in range(0,7)]for y in range(0,6)]for z in xrange(0,5)] calendar_data_f1=[[{'subtask':[],'date':0} for x in range(0,7)]for y in range(0,6)] calendar_data_f2=[[{'subtask':[],'date':0} for x in range(0,7)]for y in range(0,6)] initialize_calendar_data(mycalendar ,calendar_data[2]) initialize_calendar_data(mycalendar_f1 ,calendar_data[3]) initialize_calendar_data(mycalendar_f2,calendar_data[4]) initialize_calendar_data(mycalendar_b1 ,calendar_data[0]) initialize_calendar_data(mycalendar_b2 ,calendar_data[1]) #adding subtask in complete_data for index ,sub in enumerate(user_tasks): try: pos_to_task=int(sub.deadline.day+first_week_day)-1 calendar_data[sub.deadline.month-month+2][pos_to_task/7][pos_to_task%7]['subtask'].append(sub) except: print"some of the tasks dont have date in the given three months ,but mostly there is a cup in the function check it" return calendar_data, now ,month_name
def body(self, request): # ['', 'calendar'] # ['', 'calendar', ''] # ['', 'calendar', '2015'] # ['', 'calendar', 'abc', '123'] uris = request.uri.split('/') uris = uris[:2] uri = '/'.join(uris) return "<!DOCTYPE html><html><body><p>" + \ "<a href=\"%s/%d\"> « last year</a>" % (uri, self.year - 1) + \ " | " + \ "<a href=\"%s/%d\">next year » </a>" % (uri, self.year + 1) + \ "</p><pre>%s</pre></body></html>" % calendar(self.year)
import calendar as cal c = cal.calendar(2018) print("2018's calendar") print(c) print("calendar") year = int(input("born year in:")) month = int(input("born month in:")) print(cal.month(year, month)) print("day check-in") year = int(input("year:")) month = int(input("month:")) day = int(input("day:")) week = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] q = cal.weekday(year, month, day) print(week[q], "day")
def get_calendar(self): '''Getting calendar''' print('\n') print(calendar.calendar(self.year))
#!/usr/bin/python import calendar yr = input('What year is it? ') lilcal = calendar.calendar(yr) print("Here is a tiny calendar:") print(lilcal) if calendar.isleap(yr) == False: print('This is not a leap year') else: print('This year is a leap year')
import calendar # 日历模块 # 获取指定某个月的日历 c1 = calendar.month(2018, 8) print(c1) # 产生一个整年的日历 c2 = calendar.calendar(2018) print(c2) # 判断是否为闰年 c3 = calendar.isleap(2018) print(c3) # 返回某个月份的第一天所属的weekenday(星期N-1) 及当月总天数 c4 = calendar.monthrange(2018,8) print(c4) # 获取某个月份的日历列表,每周七天为一个元素 c5 = calendar.monthcalendar(2018,8) print(c5)
def render_GET(self, request): """ This method is called when a GET request is sent from the browser. The global number of server views (GETS) is increased by one. Method returns an HTML string displaying a nicely rendered year calender """ global server_number_of_views server_number_of_views += 1 return "<title>Calender for %s</title><html><body><pre>%s</pre></body></html>" % (self.year,calendar(self.year))
import tempfile filename = tempfile.mkdtemp() import time time.time() time.localtime(time.time()) time.asctime(time.localtime(time.time())) time.ctime() time.strftime('%c', time.localtime(time.time())) for i in range(10): print(i) time.sleep(1) import calendar print(calendar.calendar(2019)) calendar.prcal(2016) calendar.prmonth(2015, 6) calendar.weekday(2015, 6, 30) #0~6 -> 0 = 월, 1 = 화 .... 6= 일 calendar.monthrange(2015,12) import random random.random() random.randint(1, 10) random.randint(1, 55) def random_pop(data): number = random.randint(0, len(data) - 1) return data.pop(number) if __name__ == "__main__":
# monthrange (<Год>, <Месяu>) - возвращает кортеж из двух элементов: номера дня недели, # приходящегося на первое число указанного месяца, и количества дней в месяце: print(calendar.monthrange(2015, 4)) # calendar ( <Год> [, w J [, 1 J [, с J [, m] ) - возвращает текстовый календарь на указанный # год. Параметры имеют следующее предназначение: # • w - ширина поля с днем ( по умолчанию 2 ); # • 1- количество символов перевода строки между строками (по умолчанию 1); # • с - количество пробелов между месяцами (по умолчанию 6); # • m- количество месяцев на строке (по умолчанmо 3). # Значения можно указывать через запятую в порядке следования параметров или присвоить # значение названию параметра. Дnя примера выведем календарь на 2015 год так, чтобы # на одной строке выводилось сразу четыре месяца. У становим при этом количество # пробелов между месяцами: print(calendar.calendar(2015, m=4, c=2)) # рrсаl(<Год>[, w] [, 1] [, с][, m]) -функция аналогична функции calendar(), но не # возвращает календарь в виде строки, а сразу выводит его. Для примера выведем календарь # на 2015 год по два месяца на строке. Расстояние между месяцами установим равным # 4 символам, ширину поля с датой равной 2 символам, а строки разделим одним # символом перевода строки: calendar.prcal(2015, 2, 1, 4, 2) # weekheader (<n>) - возвращает строку, которая содержиr аббревиаl)'Ры дней недели с учетом # текущей локали, разделенные пробелами. Единственный параметр задает длину каждой аббре # вюпуры в символах. calendar.weekheader(4) # 'Mon Tue Wed Thu Fri Sat Sun ' calendar.weekheader(2)
import calendar year = int(input("Enter year: ")) month = int(input("Enter month: ")) print(calendar.month(year, month)) print(calendar.calendar(year))
import calendar """ 日历模块 """ # 返回某年某月日历 print(calendar.month(1982, 2)) # 返回某年的日历 print(calendar.calendar(2021)) # 判断是否闰年,返回True,否则返回False print(calendar.isleap(2000)) # 返回某个月的weekday的第一天(日历表前面空几天)和这个月所有的天数 print(calendar.monthrange(2021, 2)) # 返回某个月以每一周为元素的列表 (前后空于用0添加) print(calendar.monthcalendar(2021, 2))
''' 1 time.timezone Attribute time.timezone is the offset in seconds of the local time zone (without DST) from UTC (>0 in the Americas; <=0 in most of Europe, Asia, Africa). 2 time.tzname Attribute time.tzname is a pair of locale-dependent strings, which are the names of the local time zone without and with DST, respectively. ''' #Calendar methods ''' 1 calendar.calendar(year,w = 2,l = 1,c = 6) Returns a multiline string with a calendar for year year formatted into three columns separated by c spaces. w is the width in characters of each date; each line has length 21*w+18+2*c. l is the number of lines for each week. 2 calendar.firstweekday( ) Returns the current setting for the weekday that starts each week. By default, when calendar is first imported, this is 0, meaning Monday. 3 calendar.isleap(year) Returns True if year is a leap year; otherwise, False.
import itertools #priting summation using accumulate() print("The summation of list using accumulate is :", end="") print(list(itertools.accumulate(lis, lambda x, y: x + y))) """Eval in python""" #eval(expression, globals=None, locals=None) #expression: this string is parsed and evaluated as a Python expression #globals (optional): a dictionary to specify the available global methods and variables. #locals (optional): another dictionary to specify the available local methods and variables. x = 1 y = 2 z = eval('x+y') # in this we use the expression type(z) import struct struct.pack('i', 2) #gives the structure struct.unpack('s', '11') import calendar # using calender to print calendar of year # prints calendar of 2012 print("The calender of year 2012 is : ") print(calendar.calendar(2012, 2, 1, 6)) #using firstweekday() to print starting day number print("The starting day number in calendar is : ", end="") print(calendar.firstweekday())
# -*- coding: utf-8 -*- import calendar # 返回指定某年某月的日历 print(calendar.month(2018, 7)) # 返回指定年的所有日历 print(calendar.calendar(2018)) # 判断是否是闰年 返回true,否则返回false print(calendar.isleap(2000), calendar.isleap(2018)) # 返回的第一个参数是 每个月的第一天所在的是星期几, 第二参数是所有的天数 # print(calendar.monthrange(2018, 7)) # 返回某个月以周为单位的列表(每周是一个元素) print(calendar.monthcalendar(2018, 7))
import time tick=time.time() print(tick) localtime = time.localtime(time.time()) print ("Local current time :", localtime) localtime=time.asctime(time.localtime(time.time())) print(localtime) import calendar cal=calendar.month(2019,1) print(cal) ti=time.clock() print(ti) #time.sleep(10) call=calendar.calendar(2003,2,1,5) print(call) print(calendar.leapdays(1,12)) print("2009 is a leap year:",calendar.isleap(2009))
# print(p.cmdline()) # print(p.ppid()) # print(p.parent()) # print(p.children()) # print(p.username()) # print(p.create_time()) # print(p.terminal()) # print(p.cpu_times()) # print(p.memory_info()) # print(p.open_files()) # print(p.connections()) # print(p.num_threads()) # print(p.threads()) # print(p.environ()) # print(p.terminate()) import calendar print(calendar.isleap(2016)) print(calendar.calendar(2018)) print(calendar.month(2018,2)) print(calendar.firstweekday()) print(calendar.leapdays(2000,2018)) # calendar.prcal(2018) # calendar.prmonth(2018,2,2,1) print(calendar.weekday(2018, 2, 7)) print(calendar.monthcalendar(2018,2))
import calendar yy = int(input()) print(calendar.calendar(yy))
def render_GET(self, request): return "<html><pre>%s</pre></html>" % (calendar(self.year),)
print "以下输出2016年1月份的日历:" print cal; timeEnd = time.clock(); timeLine = timeEnd - timeStart print timeLine a = "Sat Mar 28 22:24:24 2016" print time.strptime(a,"%a %b %d %H:%M:%S %Y") print print print cal = calendar.calendar(2016,2,1,6) print cal print calendar.monthrange(2016,1)#星期一是0 print calendar.monthrange(2016,2)#星期二是1 print calendar.monthrange(2016,3) print calendar.monthrange(2016,4)
def render_GET(self, request): page = ("<html><body><pre>%s</pre></body></html>" % (calendar(self.year),)) return page.encode('utf-8')
# from sys import argv nums = argv[1:] for index, value in enumerate(nums): nums[index] = float(value) print sum(nums) # $ python sum.py 3 4 5 11 > 23.0 argv[0] is .py itself #1.pydoc import calendar year = calendar.calendar(2008) print year print calendar.isleap(2008) import math print math.ceil(22.4) print math.floor(-13.6) from math import sqrt print sqrt(2) import copy a = [1, 2, 3, 4, ['a', 'b']] #origin b = a #assignment
#!/usr/bin/env python3 import calendar import locale locale.setlocale(locale.LC_ALL, 'pl_PL') print(calendar.calendar(2017))
print(datetime.datetime.now() + datetime.timedelta(minutes=30)) # 返回时间在当前时间上 +30 分钟 c_time = datetime.datetime.now() print(c_time) # 当前时间为 2017-05-07 22:52:44.016732 print(c_time.replace(minute=3, hour=2)) # 时间替换 替换时间为‘2017-05-07 02:03:18.181732’ print(datetime.timedelta) # 表示时间间隔,即两个时间点之间的长度 print(datetime.datetime.now() - datetime.timedelta(days=5)) # 返回时间在当前时间上 -5 天 print('\n---------------------module:calendar--------------------') # python 日历模块 import calendar print(calendar.calendar(theyear=2017)) # 返回2017年整年日历 print(calendar.month(2017, 5)) # 返回某年某月的日历,返回类型为字符串类型 calendar.setfirstweekday(calendar.WEDNESDAY) # 设置日历的第一天(第一天以星期三开始) cal = calendar.month(2017, 4) print(cal) print(calendar.monthrange(2017, 5)) # 返回某个月的第一天和这个月的所有天数 print(calendar.monthcalendar(2017, 5)) # 返回某个月以每一周为元素的序列 cal = calendar.HTMLCalendar(calendar.MONDAY) print(cal.formatmonth(2017, 5)) # 在html中打印某年某月的日历 print(calendar.isleap(2017)) # 判断是否为闰年 print(calendar.leapdays(2000, 2017)) # 判断两个年份间闰年的个数
def render_GET(self, request): return '<html><body><pre>%s</pre></body></html>' % calendar.calendar(self.year)
import calendar print(calendar.calendar(2000))
#to display calendar for entire year from calendar import calendar year = int(input('Enter year :')) print(calendar(year, 2, 1, 8, 3))
# 21 22 23 24 25 26 27 # # 28 29 30 31 # # calendar.prmonth(2019, 1) # January 2019 # Mo Tu We Th Fr Sa Su # 1 2 3 4 5 6 # 7 8 9 10 11 12 13 # 14 15 16 17 18 19 20 # 21 22 23 24 25 26 27 # 28 29 30 31 print(calendar.calendar(2019)) # 2019 # # January February March # Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su # 1 2 3 4 5 6 1 2 3 1 2 3 # 7 8 9 10 11 12 13 4 5 6 7 8 9 10 4 5 6 7 8 9 10 # 14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17 # 21 22 23 24 25 26 27 18 19 20 21 22 23 24 18 19 20 21 22 23 24 # 28 29 30 31 25 26 27 28 25 26 27 28 29 30 31 # # April May June # Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su # 1 2 3 4 5 6 7 1 2 3 4 5 1 2 # 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9 # 15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16
from tkinter import * import calendar root = Tk() root.title("mange your year") year = 2020 mycal = calendar.calendar(year) cal_year = Label(root, text=mycal, font="Consolas 10 bold") cal_year.pack() root.mainloop()
ticks = time.time() print("当前时间戳为: ", ticks) localtime = time.localtime(time.time()) print("本地时间为: ", localtime) localtime = time.asctime(time.localtime(time.time())) print("本地时间为: ", localtime) print("*****格式化日期*****") # 格式化成 2016-03-20 11:45:39 形式 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) # 格式化成 Sat Mar 28 22:24:24 2016 形式 print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())) # 将格式字符串转换为时间戳 a = "Sat Mar 28 22:24:24 2016" print(time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y"))) print("获取某月日历") cal = calendar.month(2016, 1) print("以下输出2016年1月份的日历:") print(cal) print("Start : %s" % time.ctime()) time.sleep(5) print("End : %s" % time.ctime()) yearcal = calendar.calendar(2018, 2, 1, 6) print(yearcal)
import calendar from tkinter import * year = int(input("Enter Year")) root = Tk() root.geometry("1000x1000") root.title("My 2020 Calendar") myCal = calendar.calendar(year) calYear = Label(root, text=myCal, font="gothic 15 bold") calYear.pack() root.mainloop()
def get_calendar(year): return calendar.calendar(year)
import calendar print(calendar.calendar(1901)) x = calendar.Calendar() ans = 0 for i in range(1901, 2001): for j in range(1, 13): if x.monthdayscalendar(i, j)[0][6] == 1: ans += 1 print(ans)
print(time.asctime(time.localtime(time.time()))) print('=' * 50) print(time.ctime()) print('=' * 50) print(time.strftime('%x', time.localtime())) # time.sleep : 시간 잠시 멈춤 for i in range(10): print(i) # time.sleep(1) # 1이면 1초씩 멈춤 print('=' * 50) # ==================== calendar ==================== import calendar print(calendar.calendar(2019)) print('=' * 50) calendar.prcal(2015) print('=' * 50) print(calendar.weekday(2019, 12, 23)) # 0: 월, 1: 화, ... , 6:일 print(calendar.monthrange(2019, 12)) # (6, 31) 가 출력된다 첫째날은 6: 일요일이고 31일까지 있음을 알려준다. print('=' * 50) # ==================== random ==================== import random print(random.random()) # 0.0 ~ 1.0 사이의 실수 print(random.randint(1, 10)) # 1 ~ 10 사이의 정수 print('=' * 50)
def test_output(self): self.assertEqual( self.normalize_calendar(calendar.calendar(2004)), self.normalize_calendar(result_2004_text) )
""" date_time_playground.py This program is used to experiment various methods related to date and time functionality. @author: Can Akman @ the Laboratory @version: 30.12.2017_v1.0 """ import datetime, time, calendar # Get the current date (requires "datetime" module): currentDate = datetime.date.today() # Get the current local time (requires "time" module): currentTime = time.asctime(time.localtime()) # Get the calendar for a specific month (requires "calendar" module): monthCalendar = calendar.month(2018, 1) # Get the calendar for the year: calendarOne = calendar.calendar(2018, w=2, l=1, c=5) # Sleep for given number of seconds: time.sleep(1)
def calendar_of_year(year): print(calendar.calendar(year))
print(time.localtime(time.time())) print(time.ctime()) print(time.asctime(time.localtime(time.time()))) print(time.strftime('%x', time.localtime(time.time()))) print(time.strftime('%a', time.localtime(time.time()))) t1 = time.time() for i in range(10, -1, -1): print(i, end=" ") #time.sleep(1) #sleep(초) 초단위 지연 t2 = time.time() print("\n실행시간:", t2 - t1) #calendar import calendar print(calendar.calendar(2020)) print(calendar.prmonth(2020, 9)) #None #random : 난수 import random print(random.random()) print(random.randint(1, 6)) r1 = [] for i in range(1, 7): r1.append(random.randint(1, 6)) print("주사위를 던집니다!") #time.sleep(1) print(r1) r2 = [1, 2, 3, 4, 5, 6] r3 = []
#time & calendar import time, calendar tick = time.time() localTime = time.localtime(tick) localTime1 = time.asctime(localTime) print tick print localTime print localTime1 print time.timezone, time.tzname cal = calendar.month(2016, 3) print cal print calendar.monthcalendar(2016, 3) print calendar.calendar(2016) #函数 def funcSum ( arg1, arg2 ): "返回两个数的和" total = arg1 + arg2 return total lmdSum = lambda a1, a2: a1 + a2 #匿名函数 lambda表达式 print funcSum(11, 12) print lmdSum(11, 12) total = 0
#!/usr/bin/python3 import locale, datetime locale.setlocale(locale.LC_ALL, 'hu_HU.UTF-8') import calendar out = calendar.calendar(datetime.datetime.now().year) out = out.replace('h k sz cs p sz v ', ' h k sz cs p sz v') out = out.replace('h k sz cs p sz v\n', ' h k sz cs p sz v\n') print(out)
def print_in_paper(str1): # set monthly calendar so it will start with a Saturday cd.setfirstweekday(cd.SATURDAY) try: hDC = win32ui.CreateDC() print win32print.GetDefaultPrinter() # test hDC.CreatePrinterDC(win32print.GetDefaultPrinter()) hDC.StartDoc("Test doc") hDC.StartPage() hDC.SetMapMode(win32con.MM_TWIPS) # draws text within a box (assume about 1400 dots per inch for typical HP printer) ulc_x = 20 # give a left margin ulc_y = -20 # give a top margin lrc_x = 21500 # width of text area-margin, close to right edge of page lrc_y = -25000 # height of text area-margin, close to bottom of the page hDC.DrawText(str1, (ulc_x, ulc_y, lrc_x, lrc_y), win32con.DT_LEFT) hDC.EndPage() hDC.EndDoc() except: print "Printer not online" # does not work! if __name__ == '__main__': #str1 = u"����" # put a year's monthly calendars into a string str1 = cd.calendar(2008) #str1 = "Hello William!\n" raw_input('make sure printer is ready then hit enter key ... ') print_in_paper("XXXXXXXXXXXXXXXXXXXXXXXXXX")
import calendar ''' 日历模块 ''' #返回指定某年某月的月历 print(calendar.month(2017, 7)) #返回指定某年的日历 print(calendar.calendar(2017)) #闰年返回True,否则返回False print(calendar.isleap(2020)) #返回某个月的weekday的第一天和这个月所有的天数 print(calendar.monthrange(2017, 9)) #返回某个月以每一周为元素的列表 print(calendar.monthcalendar(2017, 7))
#!/usr/bin/env python # Module: py_cal.py # Purpose: calendar test # Date: N/A # Notes: # 1) # Ref: any references # import calendar calendar.setfirstweekday(calendar.SUNDAY) yr=2015 mycal = calendar.calendar(yr) print "Mycal=", mycal print "Is leap=", calendar.isleap(yr) dow=calendar.weekday(yr,10,31) print "Halloween is on: ", dow
#3 格式化 print time.asctime(time.localtime(time.time())) #获取格式化的时间 #4 日历 import calendar print calendar.month(2015, 9) #获取某年某月的日历 # Time模块的内置函数 print time.clock() #用浮点数计算返回CPU当前时间,用来衡量不同程序的耗时。 time.sleep(1) #推迟调用程序的运行,参数为秒(sec) print time.clock() # Calendar日历模块的内置函数 print calendar.calendar(2015, 1, 1, 5) #返回一个多行字符串格式的某年年历 calendar.setfirstweekday(6) #设置每个星期的第一天是星期几 print calendar.firstweekday() #返回当前每个星期的第一天是星期几 print calendar.isleap(2015) #返回是否是闰年 ### 函数 ### print "=======================" #1 必备参数 def printStr1(str): "输出任意传入的字符串" return str
def copy_file(source, destination): infile = open(source, "r") outfile = open(destination, "w") while True: text = infile.read(50) if text == "": break outfile.write(text) infile.close() outfile.close() return print(calendar.calendar(2008)) for i in range(2000, 2010): print(i, " is leap year: ", calendar.isleap(i)) print(sys.platform) print(sys.path) print(sys.version) print(sys.argv) print(dir(sys)) print(string.capwords("what's all this, then, amen")) myfile = open("test.dat", "w") print(myfile)
time.time( ) 返回当前时间的时间戳(1970纪元后经过的浮点秒数)。 time.tzset() 根据环境变量TZ重新初始化时间相关设置。 ******重要的******* time.timezone 属性time.timezone是当地时区(未启动夏令时)距离格林威治的偏移秒数(>0,美洲;<=0大部分欧洲,亚洲,非洲)。 time.tzname 属性time.tzname包含一对根据情况的不同而不同的字符串,分别是带夏令时的本地时区名称,和不带的。 """ """ # 17.7 日历(Calendar)模块 calendar.calendar(year,w=2,l=1,c=6) 返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。 calendar.firstweekday( ) 返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。 calendar.isleap(year) 是闰年返回True,否则为false。 calendar.leapdays(y1,y2) 返回在Y1,Y2两年之间的闰年总数。 calendar.month(year,month,w=2,l=1)
import time print "no of ticks since: 12 am , 1 jan ,1970 :" ,time.time() print time.localtime(time.time())#gives u time tuple ,calc tuple using sec rom 1jan 1970 12 am print time.asctime(time.localtime(time.time())) #for getting formated time , it takes ardument as time tuple import calendar print calendar.month(2016,7) print time.altzone#no idea what it is giving a= time.time() b=time.clock() #time.sleep(1.5) print time.clock()-b #gives process time print time.time()-a#gives total time print time.ctime() print time.gmtime() #provides time structure print time.mktime(time.localtime(time.time()))#convert the time tuple in secs #print time.strftime( %b%d %Y %H %M %S, time.gmtime(time.time())) check errors print calendar.calendar(1,w=2,l=1,c=6)
def Year_calendar(): """This function is used to print the calendar of a given year""" Year = int(input("Enter a year --> ")) print(calendar(Year, 3))
#!/usr/bin/python import time import calendar #calender in python print(calendar.month(2015,12)) #print calender of full year ... calender.calender( year , day width ,each week occupy no. line , width btwn months ) print(calendar.calendar(2016 , 2 , 1 , 10)) time.sleep(3) #leap year print"Check leap 2008 : " , calender.isleap(2008) time.sleep(4) print"time.time() : " , time.time() print"time.localtime(time.time()) : " , time.localtime(time.time()) print"time.asctime() : " , time.asctime() #make time function mytuple=(1923,4,2,14,23,12,0,0,0) time.mktime(mytuple) print"mktime localtime : " , time.localtime(time.mktime(mytuple)) #sleep method in python
import calendar print(calendar.month(2018, 12)) print(calendar.nextmonth(2018, 5)) print(calendar.calendar(2012))
import calendar #PARA ELEGIR EL AÑO DESEADO año = int(input("Ingrese el año: ")) print(calendar.calendar(año)) # PARA ELEGIR EL AÑO Y MES DESEADO y = int(input("Ingrese el año: ")) m = int(input("Ingrese el mes: ")) print(calendar.month(y, m))
print('\n-----------------------------------------------------------------') print('\n') print(calendar.month(2017, 9, w=5, l=2)) #kalendarz na dany miesiąc danego roku, print('\n-----------------------------------------------------------------') print('\n') print(calendar.month(2017, 9)) #bez karqs - bardziej kompaktowy kalendarz print('\n-----------------------------------------------------------------') print('\n') print('week day is', calendar.weekday(2018, 5, 7)) #zwraca który to był dzień tygodnia print('\n-----------------------------------------------------------------') print('\n') calendar.setfirstweekday( 6) #wplywa tylko na to od którego dnia będzie rysowany kalendarz print('\n-----------------------------------------------------------------') print('\n') print(calendar.month(2018, 5)) print('\n-----------------------------------------------------------------') print('\n') print('is 2020 a leap year?', calendar.isleap(2020)) #zwraca czy podany rok jest przestępny print('\n-----------------------------------------------------------------') print('\n') print('Leap days 2000-2017', calendar.leapdays(2000, 2017)) print('Leap days 2017-2020', calendar.leapdays(2000, 2020)) print('Leap days 2020-2021', calendar.leapdays( 2000, 2021)) # zwraca ilość dni prestępnych w podanym zakresie lat print(calendar.calendar(2022))