title
Python Tutorial: Datetime Module - How to work with Dates, Times, Timedeltas, and Timezones

description
In this Python Tutorial, we will be learning how to use the datetime module. The datetime module is important to understand, because you will be working with dates and times in just about every application you write. We will look at how to work with dates, times, datetimes, timedeltas, and timezones. Let's get started. The code from this video can be found at: https://github.com/CoreyMSchafer/code_snippets/tree/master/Datetime ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python

detail
{'title': 'Python Tutorial: Datetime Module - How to work with Dates, Times, Timedeltas, and Timezones', 'heatmap': [{'end': 203.637, 'start': 145.732, 'weight': 0.701}, {'end': 270.452, 'start': 217.082, 'weight': 0.758}, {'end': 485.618, 'start': 406.414, 'weight': 1}, {'end': 534.936, 'start': 512.177, 'weight': 0.72}, {'end': 807.527, 'start': 747.119, 'weight': 0.883}, {'end': 1506.94, 'start': 1434.25, 'weight': 0.836}], 'summary': 'This python tutorial covers the importance of working with dates, manipulating date and time, handling time zones, and datetime manipulation, providing practical examples and emphasizing efficient date handling practices.', 'chapters': [{'end': 76.482, 'segs': [{'end': 56.719, 'src': 'embed', 'start': 15.538, 'weight': 0, 'content': [{'end': 24.583, 'text': "So for example, in Python, we have dates, times, date times, time zones, time deltas, and it's not really obvious when we should use what.", 'start': 15.538, 'duration': 9.045}, {'end': 28.685, 'text': "So let's go ahead and dive in and look at some examples of this to get more comfortable.", 'start': 25.043, 'duration': 3.642}, {'end': 33.967, 'text': 'So the main module for working with dates in Python is the date time module.', 'start': 29.125, 'duration': 4.842}, {'end': 37.789, 'text': 'And we can import that just by saying import date time.', 'start': 34.308, 'duration': 3.481}, {'end': 44.813, 'text': 'Now the first thing to talk about when working with dates and times is understanding the difference between naive and aware date times.', 'start': 38.17, 'duration': 6.643}, {'end': 46.634, 'text': "And you'll hear these two terms a lot.", 'start': 45.113, 'duration': 1.521}, {'end': 53.597, 'text': "Now naive dates and times don't have enough information to determine things like time zone or daylight savings times.", 'start': 47.114, 'duration': 6.483}, {'end': 56.719, 'text': "But they're easier to work with if you don't need that level of detail.", 'start': 53.997, 'duration': 2.722}], 'summary': "Python's datetime module handles dates, times, time zones, and time deltas, distinguishing between naive and aware date times.", 'duration': 41.181, 'max_score': 15.538, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ15538.jpg'}], 'start': 0.229, 'title': 'Python date handling basics', 'summary': 'Introduces the importance of working with dates in python, covers different types of dates and times, and explains the difference between naive and aware date times, emphasizing the ease of working with naive dates initially.', 'chapters': [{'end': 76.482, 'start': 0.229, 'title': 'Python date handling basics', 'summary': 'Introduces the importance of working with dates in python, covers the different types of dates and times, and explains the difference between naive and aware date times, emphasizing the ease of working with naive dates initially.', 'duration': 76.253, 'highlights': ["The main module for working with dates in Python is the date time module, which can be imported using 'import datetime'.", 'The chapter emphasizes the importance of understanding the difference between naive and aware date times, explaining that naive dates and times are easier to work with, while aware dates and times have enough information to determine time zone and daylight savings time.', "Naive dates and times don't have enough information to determine things like time zone or daylight savings times, making them easier to work with if that level of detail is not needed."]}], 'duration': 76.253, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ229.jpg', 'highlights': ["The main module for working with dates in Python is the date time module, which can be imported using 'import datetime'.", 'The chapter emphasizes the importance of understanding the difference between naive and aware date times, explaining that naive dates and times are easier to work with, while aware dates and times have enough information to determine time zone and daylight savings time.', "Naive dates and times don't have enough information to determine things like time zone or daylight savings times, making them easier to work with if that level of detail is not needed."]}, {'end': 443.61, 'segs': [{'end': 106.557, 'src': 'embed', 'start': 77.463, 'weight': 4, 'content': [{'end': 82.79, 'text': "so with a normal date we're going to be working with a year, month and day.", 'start': 77.463, 'duration': 5.327}, {'end': 86.074, 'text': 'now there are a couple of different ways that we can create a date.', 'start': 82.79, 'duration': 3.284}, {'end': 96.187, 'text': "but to create a date right now i'm just going to do a date time, dot date and i'm going to pass in a year, a month and a day.", 'start': 86.074, 'duration': 10.113}, {'end': 100.751, 'text': "So now, let's go ahead and print this out so we can see what this looks like.", 'start': 96.607, 'duration': 4.144}, {'end': 106.557, 'text': 'So you can see that when we printed that out, that it gave us a date of 2016-07-24.', 'start': 101.192, 'duration': 5.365}], 'summary': 'Creating a date with year, month, and day resulted in 2016-07-24.', 'duration': 29.094, 'max_score': 77.463, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ77463.jpg'}, {'end': 203.637, 'src': 'heatmap', 'start': 122.152, 'weight': 2, 'content': [{'end': 128.377, 'text': "and I make this mistake a lot myself, because when I write down dates, I'm used to adding in that leading zero,", 'start': 122.152, 'duration': 6.225}, {'end': 130.52, 'text': "but that's not the correct way to pass it in.", 'start': 128.377, 'duration': 2.143}, {'end': 136.065, 'text': 'So just do for single digits, just do that single digit and you can see that that works.', 'start': 130.539, 'duration': 5.526}, {'end': 139.127, 'text': 'Now we do have other ways of creating dates also.', 'start': 136.525, 'duration': 2.602}, {'end': 145.211, 'text': "So if I wanted to get today's local date, then I'm just going to call this today.", 'start': 139.527, 'duration': 5.684}, {'end': 151.155, 'text': "And instead of doing this constructor here, I'm just going to do date.today.", 'start': 145.732, 'duration': 5.423}, {'end': 157.26, 'text': "So now I'm just going to go ahead and grab this variable name here, and let's go ahead and print that out.", 'start': 152.296, 'duration': 4.964}, {'end': 160.683, 'text': 'So when I print that out, you can see that we got the current local date.', 'start': 157.561, 'duration': 3.122}, {'end': 165.027, 'text': 'Now, we also have some methods available to get more information about our dates.', 'start': 161.064, 'duration': 3.963}, {'end': 173.194, 'text': 'So if I wanted to grab just the year, month, or day, then, so for example, if I wanted to grab just the year, I could say today.year.', 'start': 165.348, 'duration': 7.846}, {'end': 176.477, 'text': 'And if I wanted to grab just the day, then I could do day.', 'start': 173.555, 'duration': 2.922}, {'end': 183.002, 'text': "Now we can also get the day of the week and there's actually two different ways that we can use this.", 'start': 177.398, 'duration': 5.604}, {'end': 189.647, 'text': 'So we can either use weekday or we can use isoweekday.', 'start': 183.382, 'duration': 6.265}, {'end': 196.372, 'text': 'So if I go ahead and print this out, you can see that for one we get a one and for the other one we get a two.', 'start': 190.228, 'duration': 6.144}, {'end': 203.637, 'text': 'So the only difference here is that for the weekday, Monday is zero and Sunday is six.', 'start': 196.772, 'duration': 6.865}], 'summary': 'Demonstrates creating and manipulating dates in python using date.today and accessing date components like year, month, day, and day of the week.', 'duration': 67.495, 'max_score': 122.152, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ122152.jpg'}, {'end': 270.452, 'src': 'heatmap', 'start': 217.082, 'weight': 0.758, 'content': [{'end': 224.904, 'text': 'So you can see that for the weekday, we got a 1, which if Monday is 0, then Tuesday, that would be correct.', 'start': 217.082, 'duration': 7.822}, {'end': 230.445, 'text': "And for the ISO weekday, Monday is 1, so Tuesday would be 2, so that's correct also.", 'start': 225.344, 'duration': 5.101}, {'end': 233.567, 'text': "Okay, so now let's take a look at time deltas.", 'start': 230.945, 'duration': 2.622}, {'end': 238.169, 'text': 'Now, time deltas are simply the difference between two dates or times,', 'start': 233.947, 'duration': 4.222}, {'end': 242.672, 'text': "and they're extremely useful when we want to do operations on our dates or times.", 'start': 238.169, 'duration': 4.503}, {'end': 248.875, 'text': 'So for example, let me create a time delta one week away, which would be seven days.', 'start': 242.952, 'duration': 5.923}, {'end': 254.859, 'text': "So I'm gonna do a time delta is equal to date time dot time delta.", 'start': 248.895, 'duration': 5.964}, {'end': 260.524, 'text': "And I'm just going to pass in a duration here of days equal to seven.", 'start': 255.16, 'duration': 5.364}, {'end': 265.388, 'text': "So now I'm going to go ahead and just get rid of these two print statements here.", 'start': 260.863, 'duration': 4.525}, {'end': 270.452, 'text': 'So now that I have this duration of seven days, I can use this to do some calculations.', 'start': 265.848, 'duration': 4.604}], 'summary': 'Explanation of weekday and time deltas for date and time operations.', 'duration': 53.37, 'max_score': 217.082, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ217082.jpg'}, {'end': 368.221, 'src': 'embed', 'start': 340.47, 'weight': 1, 'content': [{'end': 344.571, 'text': 'Okay, so this comment will make what I just said here a little bit easier to visualize.', 'start': 340.47, 'duration': 4.101}, {'end': 352.292, 'text': 'So if we add or subtract a time delta from a date, then we get another date as a result.', 'start': 344.971, 'duration': 7.321}, {'end': 359.714, 'text': "And if we add or subtract another date from a date, then we'll get a time delta as a result.", 'start': 352.673, 'duration': 7.041}, {'end': 363.137, 'text': "So let's go ahead and take a look at an example of this.", 'start': 360.174, 'duration': 2.963}, {'end': 368.221, 'text': "So let's figure out how many days there are until my birthday this year.", 'start': 363.877, 'duration': 4.344}], 'summary': 'Manipulating dates and time deltas to obtain new dates and time differences.', 'duration': 27.751, 'max_score': 340.47, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ340470.jpg'}, {'end': 418.888, 'src': 'embed', 'start': 388.819, 'weight': 0, 'content': [{'end': 395.484, 'text': "so now i'm going to create another variable here and i'm going to call this till b day.", 'start': 388.819, 'duration': 6.665}, {'end': 397.546, 'text': 'now this is going to be a time delta.', 'start': 395.484, 'duration': 2.062}, {'end': 406.414, 'text': "once we run this calculation and i'm going to say till b day is equal to my birthday, minus the current day.", 'start': 397.546, 'duration': 8.868}, {'end': 418.888, 'text': 'so now, if i print out this till b day and run that, you can see that it has 60 days as the total duration between those two dates.', 'start': 406.414, 'duration': 12.474}], 'summary': "Created a time delta variable 'till b day' with 60 days duration.", 'duration': 30.069, 'max_score': 388.819, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ388819.jpg'}], 'start': 77.463, 'title': 'Python date and time operations', 'summary': 'Covers creating and formatting dates in python, emphasizing the importance of passing regular integers for days and months without leading zeroes, and manipulating date and time, including extracting specific components, calculating time deltas, and obtaining the difference between dates and times, with practical examples.', 'chapters': [{'end': 165.027, 'start': 77.463, 'title': 'Working with dates in python', 'summary': "Covers creating and formatting dates in python, emphasizing the importance of passing regular integers for days and months without leading zeroes and demonstrating how to get today's local date using date.today, providing practical examples.", 'duration': 87.564, 'highlights': ['Creating dates using datetime.date(year, month, day) and printing the date', 'Importance of passing regular integers for days and months with no leading zero', "Getting today's local date using date.today()"]}, {'end': 443.61, 'start': 165.348, 'title': 'Python date and time operations', 'summary': 'Explains how to manipulate date and time in python, including extracting specific components such as year, month, and day, calculating time deltas, and performing operations to obtain the difference between dates and times, with examples demonstrating the practical applications and outputs.', 'duration': 278.262, 'highlights': ["Calculating the difference between two dates to find the number of days until a specific event, demonstrated with an example of determining the days until the author's birthday, yielding a total duration of 60 days.", "Explaining the process of obtaining specific components from a date, such as year, month, and day, using Python's datetime module, with examples illustrating how to extract these values.", 'Illustrating the utilization of time deltas to perform operations on dates and times, including adding or subtracting days, and obtaining the date one week ahead or behind.']}], 'duration': 366.147, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ77463.jpg', 'highlights': ['Calculating the difference between two dates to find the number of days until a specific event, yielding a total duration of 60 days.', 'Illustrating the utilization of time deltas to perform operations on dates and times, including adding or subtracting days, and obtaining the date one week ahead or behind.', "Explaining the process of obtaining specific components from a date, such as year, month, and day, using Python's datetime module, with examples illustrating how to extract these values.", "Getting today's local date using date.today()", 'Creating dates using datetime.date(year, month, day) and printing the date', 'Importance of passing regular integers for days and months with no leading zero']}, {'end': 741.258, 'segs': [{'end': 495.323, 'src': 'embed', 'start': 470.249, 'weight': 0, 'content': [{'end': 476.594, 'text': "And with datetime.time, we're going to be working with hours, minutes, seconds, and microseconds.", 'start': 470.249, 'duration': 6.345}, {'end': 480.516, 'text': "So this isn't going to include the year, the month, or the day.", 'start': 477.094, 'duration': 3.422}, {'end': 485.618, 'text': "Now by default, this doesn't have time zone information, so this is still naive.", 'start': 480.896, 'duration': 4.722}, {'end': 492.802, 'text': "But we can specify a time zone using tzinfo if we'd like, and we'll look at some time zones in just a second.", 'start': 485.999, 'duration': 6.803}, {'end': 495.323, 'text': "But for now, we're going to create a new time.", 'start': 493.162, 'duration': 2.161}], 'summary': 'Working with datetime.time for hours, minutes, seconds, and microseconds, excluding year, month, and day.', 'duration': 25.074, 'max_score': 470.249, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ470249.jpg'}, {'end': 534.936, 'src': 'heatmap', 'start': 512.177, 'weight': 0.72, 'content': [{'end': 519.466, 'text': 'So you can see that it printed out here in a nice format and just like with the date we can access these attributes individually.', 'start': 512.177, 'duration': 7.289}, {'end': 523.932, 'text': 'So if I wanted to just print out the hour then I can just print out the hour.', 'start': 519.525, 'duration': 4.407}, {'end': 532.315, 'text': 'Now to be honest, I hardly ever use datetime.time, because most of the time when I need the time of day, I also need the date,', 'start': 524.432, 'duration': 7.883}, {'end': 534.936, 'text': "and that's where datetime.datetime comes in.", 'start': 532.315, 'duration': 2.621}], 'summary': 'Demonstrating how to access and print individual attributes of datetime objects.', 'duration': 22.759, 'max_score': 512.177, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ512177.jpg'}, {'end': 598.74, 'src': 'embed', 'start': 573.402, 'weight': 1, 'content': [{'end': 583.271, 'text': "26, then i'll just do 12 for the hours, 30 for the minutes, 45 for the seconds and another 100 000 for the milliseconds,", 'start': 573.402, 'duration': 9.869}, {'end': 587.115, 'text': "and i'm going to go ahead and call this dt for date time.", 'start': 583.271, 'duration': 3.844}, {'end': 588.656, 'text': "let's go ahead and print this out.", 'start': 587.115, 'duration': 1.541}, {'end': 593.719, 'text': 'So now, if I print this out, you can see that it gave us back the entire date and the time.', 'start': 589.517, 'duration': 4.202}, {'end': 598.74, 'text': 'So we have the whole date right here and then we have the time here.', 'start': 594.179, 'duration': 4.561}], 'summary': 'Creating a date and time object with specific values and printing it out.', 'duration': 25.338, 'max_score': 573.402, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ573402.jpg'}, {'end': 653.757, 'src': 'embed', 'start': 623.811, 'weight': 2, 'content': [{'end': 628.174, 'text': "So let's say that I wanted just the year, then I can just go ahead and print out the year.", 'start': 623.811, 'duration': 4.363}, {'end': 634.618, 'text': 'And just like we did with the date, we can also add and subtract time delta duration.', 'start': 628.694, 'duration': 5.924}, {'end': 637.86, 'text': 'So let me go ahead and recreate that time delta.', 'start': 634.698, 'duration': 3.162}, {'end': 641.663, 'text': 'And the way that we did that was date time dot time delta.', 'start': 638.041, 'duration': 3.622}, {'end': 645.766, 'text': "And I'm also just going to do the days of seven again.", 'start': 642.063, 'duration': 3.703}, {'end': 653.757, 'text': "Okay, so now instead of printing out just this date time, now I'm going to add on this time delta.", 'start': 646.834, 'duration': 6.923}], 'summary': 'Demonstrating addition and subtraction of time delta in python.', 'duration': 29.946, 'max_score': 623.811, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ623811.jpg'}], 'start': 444.03, 'title': 'Working with date and time in python', 'summary': 'Covers working with datetime.date and datetime.time, manipulating time zones, creating new local time, creating date time objects, accessing specific attributes, and manipulating date and time in python, with examples and demonstrations.', 'chapters': [{'end': 573.402, 'start': 444.03, 'title': 'Working with datetime in python', 'summary': 'Covers working with datetime.date and datetime.time in python, emphasizing the attributes and functionalities of each, with a focus on manipulating time zones and creating new local time.', 'duration': 129.372, 'highlights': ['The chapter emphasizes the attributes and functionalities of datetime.date and datetime.time in Python, with a focus on manipulating time zones and creating new local time.', 'The transcript provides a detailed overview of working with datetime.date and datetime.time in Python, including their respective attributes and their usage in manipulating time zones and creating new local time.', 'It discusses the distinctions between datetime.date and datetime.time in Python, highlighting their specific attributes and use cases.']}, {'end': 623.731, 'start': 573.402, 'title': 'Working with date and time in python', 'summary': 'Demonstrates how to work with date and time in python, including creating date time objects and accessing specific attributes like date and time, with an example of printing the entire date and time. it also illustrates how to access the date without the time and vice versa, as well as how to grab individual attributes.', 'duration': 50.329, 'highlights': ['The chapter demonstrates creating a date time object with specific values for hours (12), minutes (30), seconds (45), and milliseconds (100,000), and printing out the entire date and time.', 'It shows how to access the date without the time using the method dt.date and how to grab the time using datetime.time.', 'The chapter explains the flexibility of date times in Python, allowing access to just about anything needed and the ability to grab each individual attribute.']}, {'end': 741.258, 'start': 623.811, 'title': 'Manipulating date and time in python', 'summary': 'Demonstrates how to manipulate date and time in python, including adding and subtracting time deltas, using different time durations, and exploring alternative constructors like today, now, and utcnow.', 'duration': 117.447, 'highlights': ['Demonstrated adding and subtracting time delta duration in Python.', 'Illustrated the process of adding a time delta to a given date and time.', 'Explained the usage of alternative constructors for date and time in Python.']}], 'duration': 297.228, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ444030.jpg', 'highlights': ['The chapter emphasizes the attributes and functionalities of datetime.date and datetime.time in Python, with a focus on manipulating time zones and creating new local time.', 'The chapter demonstrates creating a date time object with specific values for hours (12), minutes (30), seconds (45), and milliseconds (100,000), and printing out the entire date and time.', 'Demonstrated adding and subtracting time delta duration in Python.', 'The transcript provides a detailed overview of working with datetime.date and datetime.time in Python, including their respective attributes and their usage in manipulating time zones and creating new local time.']}, {'end': 1406.578, 'segs': [{'end': 807.527, 'src': 'heatmap', 'start': 741.618, 'weight': 1, 'content': [{'end': 746.699, 'text': 'So these millisecond differences here are just due to the small amounts of time between when they were executed.', 'start': 741.618, 'duration': 5.081}, {'end': 758.061, 'text': 'So if datetime.today and datetimenow look almost identical here, then what is the difference between these? So the difference is that .', 'start': 747.119, 'duration': 10.942}, {'end': 762.842, 'text': 'today returns the current local datetime with a time zone of none.', 'start': 758.061, 'duration': 4.781}, {'end': 767.865, 'text': 'and dot now gives us the option to pass in a time zone.', 'start': 763.522, 'duration': 4.343}, {'end': 771.488, 'text': 'So if you leave the time zone empty, then these are similar.', 'start': 768.226, 'duration': 3.262}, {'end': 781.515, 'text': 'Now, you might assume here that dot UTC now, since it has UTC in the name of the method, that this is a time zone, aware date time,', 'start': 771.888, 'duration': 9.627}, {'end': 782.816, 'text': "and that's actually not true.", 'start': 781.515, 'duration': 1.301}, {'end': 788.841, 'text': 'So this gives us the current UTC time, but the TZ info is still set to none.', 'start': 783.177, 'duration': 5.664}, {'end': 793.923, 'text': "so nothing that we've done so far has given us time zone aware date times.", 'start': 789.301, 'duration': 4.622}, {'end': 799.465, 'text': "we have to explicitly set those, so that's a good segue into looking at how to use time zones now.", 'start': 793.923, 'duration': 5.542}, {'end': 802.506, 'text': "there's a lot of different ways that we could look at using time zones,", 'start': 799.465, 'duration': 3.041}, {'end': 807.527, 'text': "but i think i'm going to go ahead and jump directly into showing you how to use pi tz now.", 'start': 802.506, 'duration': 5.021}], 'summary': 'Explanation of datetime differences and methods, emphasizing time zone awareness and use of pi tz now.', 'duration': 26.247, 'max_score': 741.618, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ741618.jpg'}, {'end': 863.194, 'src': 'embed', 'start': 833.268, 'weight': 0, 'content': [{'end': 837.192, 'text': 'But even in the Python docs here, they recommend using pyTZ.', 'start': 833.268, 'duration': 3.924}, {'end': 840.214, 'text': "So here's their justification for that.", 'start': 838.533, 'duration': 1.681}, {'end': 848.382, 'text': 'They say that the standard library has timezone class for handling arbitrary fixed offsets from UTC and timezone.UTC.', 'start': 840.255, 'duration': 8.127}, {'end': 855.668, 'text': 'PyTZ library brings in this timezone database to Python and its usage is recommended.', 'start': 849.122, 'duration': 6.546}, {'end': 863.194, 'text': "So we could use this timezone class to work with timezones, but since PyTZ is pretty easy to use and since it's more useful,", 'start': 856.108, 'duration': 7.086}], 'summary': 'Python docs recommend using pytz for timezone handling due to its ease of use and usefulness.', 'duration': 29.926, 'max_score': 833.268, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ833268.jpg'}, {'end': 1102.141, 'src': 'embed', 'start': 1058.433, 'weight': 2, 'content': [{'end': 1064.686, 'text': "And I'm actually going to go ahead and call this UTC now so that it makes a little bit more sense.", 'start': 1058.433, 'duration': 6.253}, {'end': 1068.867, 'text': "So let's look at how we can convert this to a different time zone.", 'start': 1065.146, 'duration': 3.721}, {'end': 1075.55, 'text': "So I'm currently located close to Denver in the United States, which is the mountain time zone.", 'start': 1069.248, 'duration': 6.302}, {'end': 1079.952, 'text': 'So if I wanted to convert this UTC time to my time zone,', 'start': 1075.91, 'duration': 4.042}, {'end': 1102.141, 'text': "then I could just say I'll call this DT Mountain and I'll say dt utc now dot as time zone and now we can just pass in the time zone that we want and this is going to be pi tz dot time zone and the time zone that i'm going to pass in here is us dash mountain.", 'start': 1079.952, 'duration': 22.189}], 'summary': 'Demonstrating utc to mountain time zone conversion using python', 'duration': 43.708, 'max_score': 1058.433, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1058433.jpg'}, {'end': 1231.622, 'src': 'embed', 'start': 1205.054, 'weight': 3, 'content': [{'end': 1213.837, 'text': 'What we just did here is we took a time zone aware date time set to UTC and we converted that to mountain time.', 'start': 1205.054, 'duration': 8.783}, {'end': 1219.619, 'text': 'But what if we have a naive date time and we want to make that naive date time time zone aware?', 'start': 1214.257, 'duration': 5.362}, {'end': 1226.481, 'text': "For example, let me go ahead and create a new local date time that doesn't have that time zone information.", 'start': 1220.199, 'duration': 6.282}, {'end': 1231.622, 'text': 'And remember, we can grab the local time with datetime.now.', 'start': 1226.841, 'duration': 4.781}], 'summary': 'Converted time zone from utc to mountain time and made naive date time time zone aware.', 'duration': 26.568, 'max_score': 1205.054, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1205054.jpg'}], 'start': 741.618, 'title': 'Python datetime and time zones', 'summary': 'Discusses differences between datetime.today, datetime.now, and datetime.utcnow in python, and emphasizes the importance of using the pytz library for time zone handling. it also provides practical examples and recommendations based on the python documentation.', 'chapters': [{'end': 793.923, 'start': 741.618, 'title': 'Python datetime differences', 'summary': 'Explains the differences between datetime.today, datetime.now, and datetime.utcnow in python, highlighting that datetime.today returns the current local datetime with a time zone of none, datetime.now gives the option to pass in a time zone, and datetime.utcnow provides the current utc time with tz info set to none.', 'duration': 52.305, 'highlights': ['The difference between datetime.today, datetime.now, and datetime.utcnow in Python is that datetime.today returns the current local datetime with a time zone of none, datetime.now gives the option to pass in a time zone, and datetime.utcnow provides the current UTC time with TZ info set to none.', 'The method datetime.utcnow provides the current UTC time, but the TZ info is still set to none.', 'The method datetime.now gives us the option to pass in a time zone.']}, {'end': 1406.578, 'start': 793.923, 'title': 'Working with time zones in python', 'summary': 'Explains the importance of using the pytz library for time zone handling in python, demonstrates how to create time zone aware date times using utc, convert date times to different time zones, and make naive date times time zone aware, providing practical examples and recommendations based on the python documentation.', 'duration': 612.655, 'highlights': ['The PyTZ library is recommended over the standard library for handling time zones in Python, as it brings a timezone database to Python and is considered more useful and easy to use.', 'Creating a time zone aware date time using UTC, with the demonstration of setting the date time to UTC and printing the UTC offset.', 'Conversion of UTC time to a different time zone, such as converting UTC time to mountain time, with a practical example and output comparison.', 'The process of making a naive date time time zone aware using the time zone localized function, with an example of converting a naive date time to a time zone aware date time and demonstrating the correct setting of the time in a different time zone.']}], 'duration': 664.96, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ741618.jpg', 'highlights': ['The PyTZ library is recommended over the standard library for handling time zones in Python, as it brings a timezone database to Python and is considered more useful and easy to use.', 'The difference between datetime.today, datetime.now, and datetime.utcnow in Python is that datetime.today returns the current local datetime with a time zone of none, datetime.now gives the option to pass in a time zone, and datetime.utcnow provides the current UTC time with TZ info set to none.', 'Conversion of UTC time to a different time zone, such as converting UTC time to mountain time, with a practical example and output comparison.', 'The process of making a naive date time time zone aware using the time zone localized function, with an example of converting a naive date time to a time zone aware date time and demonstrating the correct setting of the time in a different time zone.']}, {'end': 1657.974, 'segs': [{'end': 1509.161, 'src': 'heatmap', 'start': 1429.244, 'weight': 0, 'content': [{'end': 1433.87, 'text': "Now, if you're not familiar with that format, then it can look a little strange, but it is an international standard.", 'start': 1429.244, 'duration': 4.626}, {'end': 1437.814, 'text': 'Now, if you wanna print these date times out in a specific format,', 'start': 1434.25, 'duration': 3.564}, {'end': 1445.644, 'text': "then you can go to the Python documentation and look at the format codes to print these out in just about any way that you'd want.", 'start': 1437.814, 'duration': 7.83}, {'end': 1454.592, 'text': 'So, if I go down here and look at these codes, then you can see that they have what the format code is, and then the example.', 'start': 1446.064, 'duration': 8.528}, {'end': 1460.317, 'text': "So, let's say that I wanted to print it out in the form July 26, 2016.", 'start': 1454.692, 'duration': 5.625}, {'end': 1469.746, 'text': 'So, to do that, after looking at those format codes, you can use this method called strfm.', 'start': 1460.318, 'duration': 9.428}, {'end': 1475.449, 'text': 'time, and then pass in the format code.', 'start': 1471.568, 'duration': 3.881}, {'end': 1482.671, 'text': 'So the format code that I want is %B, which is the full month.', 'start': 1475.769, 'duration': 6.902}, {'end': 1485.032, 'text': '%D, which is a two-digit day.', 'start': 1482.671, 'duration': 2.361}, {'end': 1490.834, 'text': "then I'm going to put in a comma and then a %Y, which will be the full year.", 'start': 1485.032, 'duration': 5.802}, {'end': 1496.134, 'text': 'So if I print that, then you can see that it prints out July 26, 2016.', 'start': 1491.234, 'duration': 4.9}, {'end': 1497.516, 'text': "Now you don't have to memorize these.", 'start': 1496.135, 'duration': 1.381}, {'end': 1498.596, 'text': "I've never memorized these.", 'start': 1497.576, 'duration': 1.02}, {'end': 1501.878, 'text': 'Every time I want to print something out in a specific format,', 'start': 1498.996, 'duration': 2.882}, {'end': 1506.94, 'text': 'I always go to the documentation and find the format codes that I want and then print them out that way.', 'start': 1501.878, 'duration': 5.062}, {'end': 1509.161, 'text': 'Now sometimes you have the opposite.', 'start': 1507.44, 'duration': 1.721}], 'summary': 'Python provides format codes for printing date times in specific formats, like july 26, 2016.', 'duration': 79.917, 'max_score': 1429.244, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1429244.jpg'}, {'end': 1637.51, 'src': 'embed', 'start': 1615.091, 'weight': 2, 'content': [{'end': 1622.679, 'text': 'Now I should mention that there is a popular Python package called Arrow that is supposed to be an easier way to work with datetimes,', 'start': 1615.091, 'duration': 7.588}, {'end': 1625.642, 'text': "and maybe I'll try to do a video of that in the near future.", 'start': 1622.679, 'duration': 2.963}, {'end': 1632.729, 'text': 'But I hope that knowing these basics of the built-in datetime module, that it will allow you to solve most of the problems that you come up against.', 'start': 1626.022, 'duration': 6.707}, {'end': 1637.51, 'text': 'But if you do have any questions about what we covered in this video, then just feel free to ask in the comment section below,', 'start': 1633.129, 'duration': 4.381}], 'summary': 'Arrow python package simplifies datetime handling; built-in module covers most problems.', 'duration': 22.419, 'max_score': 1615.091, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1615091.jpg'}, {'end': 1657.974, 'src': 'embed', 'start': 1646.172, 'weight': 4, 'content': [{'end': 1649.612, 'text': "and also it's a huge help to share these videos with anyone who you think would find them useful.", 'start': 1646.172, 'duration': 3.44}, {'end': 1654.753, 'text': "And if you have the means, you can contribute through Patreon, and there's a link to that page in the description section below.", 'start': 1650.072, 'duration': 4.681}, {'end': 1657.974, 'text': 'Be sure to subscribe for future videos, and thank you all for watching.', 'start': 1655.473, 'duration': 2.501}], 'summary': 'Encourage sharing videos, contributing through patreon, subscribing for future content.', 'duration': 11.802, 'max_score': 1646.172, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1646172.jpg'}], 'start': 1407.019, 'title': 'Date time manipulation in python', 'summary': "Covers saving, displaying, and formatting date times in python using iso format and python documentation's format codes, converting strings to datetime objects, and introducing the python package arrow for datetime handling. it also encourages support through likes, shares, and patreon contributions.", 'chapters': [{'end': 1501.878, 'start': 1407.019, 'title': 'Displaying date times in python', 'summary': "Explains the best way to save and display date times in python using iso format, and also demonstrates how to print date times in a specific format using python documentation's format codes, such as displaying the date as july 26, 2016.", 'duration': 94.859, 'highlights': ['The best way to save and pass date times for internal use in Python is using the ISO format, which is an international standard.', 'Python provides format codes that allow users to print date times in various specific formats, and the example demonstrated printing the date as July 26, 2016 using the format codes %B for the full month, %D for a two-digit day, and %Y for the full year.']}, {'end': 1657.974, 'start': 1501.878, 'title': 'Working with dates and times in python', 'summary': 'Explains how to convert strings to datetime objects using the datetime module in python, also mentioning a popular python package called arrow for easier datetime handling, and encourages support through likes, shares, and patreon contributions.', 'duration': 156.096, 'highlights': ['The chapter explains how to convert strings to datetime objects using the datetime module in Python, with a demonstration of the strptime function, and mentions a popular Python package called Arrow for easier datetime handling.', 'Encourages support through likes, shares, and Patreon contributions, and emphasizes the importance of subscribing for future videos.', 'Provides guidance on solving problems related to working with dates and times in Python using the built-in datetime module.']}], 'duration': 250.955, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/eirjjyP2qcQ/pics/eirjjyP2qcQ1407019.jpg', 'highlights': ['The best way to save and pass date times in Python is using the ISO format, an international standard.', 'Python provides format codes for printing date times in specific formats, e.g., %B for full month, %D for two-digit day, and %Y for full year.', 'The chapter explains converting strings to datetime objects using the datetime module in Python and introduces the popular package Arrow for datetime handling.', 'Guidance on solving problems related to working with dates and times in Python using the built-in datetime module.', 'Encourages support through likes, shares, and Patreon contributions for future videos.']}], 'highlights': ['Calculating the difference between two dates to find the number of days until a specific event, yielding a total duration of 60 days.', 'The PyTZ library is recommended over the standard library for handling time zones in Python, as it brings a timezone database to Python and is considered more useful and easy to use.', 'The chapter emphasizes the attributes and functionalities of datetime.date and datetime.time in Python, with a focus on manipulating time zones and creating new local time.', 'The best way to save and pass date times in Python is using the ISO format, an international standard.', 'Illustrating the utilization of time deltas to perform operations on dates and times, including adding or subtracting days, and obtaining the date one week ahead or behind.']}