Introduction to Programming with Python Date and Time



































- Slides: 35
Introduction to Programming with Python Date and Time සමඟ ව ඩකරන හ ට Dileepa Rajapaksa | http: //www. windowsgeek. lk @dsrajapaksa Microsoft Virtual Academy
Demo කලන Microsoft Virtual Academy Video එක අභය ගයට පළතර
දන සහ ව ල වන කරම Date. Time Microsoft Virtual Academy සමග ව ඩ
තමනග උපනදනයට ඇත දන ගණන ස ය ග නමට අවශ යනම මලනම අද දනය ද නගතයතය. • datetime කයන class එක මගන අපට අද දනය ලබ ගනන පළවන . #The import statement gives us access to #the functionality of the datetime class import datetime #today is a function that returns today's date print (datetime. date. today()) Microsoft Virtual Academy
දනයන පළවන variable වල ගබඩ කරනන. import datetime #store the value in a variable called current. Date = datetime. date. today() print (current. Date) Microsoft Virtual Academy
Demo ද න ව ල ව හ දනය ප නවම Microsoft Virtual Academy
දනය හ ඇත ව නස ක ටස ඔබට භ වත කරනන පළවන. import datetime current. Date = datetime. date. today() print (current. Date. year) print (current. Date. month) print (current. Date. day) Microsoft Virtual Academy
Demo දනය හ ක ටස භ වතය භ වත කරම Microsoft Virtual Academy සඳහ date functions එක
Date formats Microsoft Virtual Academy
2/5/2014 මගන දවසද? Microsoft Virtual Academy ප නවනන ම න
Python වලද strftime භ වත කරල format එක ව නසකරනන පළවන import datetime current. Date = datetime. date. today() #strftime allows you to specify the date format print (current. Date. strftime('%d %b, %Y')) Microsoft Virtual Academy date.
Demo Formatting dates Microsoft Virtual Academy
Wedding Invitation එකක print කරනන පළවනද ? “Please attend our event Sunday, July 20 in the year 1997” import datetime current. Date = datetime. date. today() #strftime allows you to specify the date format print (current. Date. strftime ('Please attend our event %A, %B %d in the year %Y')) Microsoft Virtual Academy
strptime function එක මගන එකක දනයක ඔබට පළවන බවට පරවරතනය කරනන string import datetime birthday = input ("What is your birthday? ") birthdate = datetime. strptime(birthday, "%m/%d/%Y"). date() #why did we list datetime twice? #because we are calling the strptime function #which is part of the datetime class #which is in the datetime module print ("Your birth month is " + birthdate. strftime('%B')) Microsoft Virtual Academy
Demo User ග න Microsoft Virtual Academy date value එකක ලබ ග නම
අවල වග ද? , ඒක වටනවද ? ඇය ඒව string වදහට store කරනන. Dates ටකක න තත • ඔය ලට ල ක උතසවයකට හ නව ඩවකට ඇත දන ගණන ප නවමට countdown එකක හදනන පළවන next. Birthday = datetime. strptime(‘ 02/04/2016', '%m/%d/%Y'). date() current. Date = datetime. date. today() #If you subtract two dates you get back the number of days #between those dates difference = next. Birthday - current. Date print (difference. days) Microsoft Virtual Academy
Dates ටකක අවල වග ද? , ඒක වටනවද ? ඇය න තත ඒව string වදහට store කරනන. • ශතකරණය තය න ද රව යවල කල ඉකතවන දනයප නවම current. Date = datetime. date. today() #timedelta allows you to specify the time #to add or subtract from a date print (current. Date + datetimedelta(days=15)) print (current. Date + datetimedelta(hours=15)) Microsoft Virtual Academy
ව ල ව සමග ව ඩකරම Microsoft Virtual Academy
ව ල ව ග න ම කද? • Datetime කයන එක අපට ව ල වත පළවන. import datetime current. Time = datetime. now() print (current. Time. hour) print (current. Time. minute) print (current. Time. second) Microsoft Virtual Academy store කරනන
dates වග ම time format කරනනත භ වත කරනන පළවන . strftime() import datetime current. Time = datetime. now() print (datetime. strftime(current. Time, '%H: %M')) %H ප ය ( ප ය 24 ව ල ව න ( %I ( ප ය 12 ව ල ව න %p AM හ PM %m මනතත %S තතපර Microsoft Virtual Academy
Demo ව ල වන සමග ව ඩකරම Microsoft Virtual Academy
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.