Date and Time Fundamentals

This course will help you to understand dates and times, and how they should be used in software development.
Course info
Rating
(204)
Level
Intermediate
Updated
Sep 13, 2014
Duration
6h 19m
Table of contents
Introduction and Basic Concepts
Context Matters
Time Zones
Date and Time Formats
Date and Time in the .NET Framework
Introducing Noda Time
Date and Time in JavaScript
Date and Time in Other Programming Languages
Common Mistakes and Best Practices
Description
Course info
Rating
(204)
Level
Intermediate
Updated
Sep 13, 2014
Duration
6h 19m
Description

Managing dates and times properly is one of the most difficult things to get right in software. This is mostly due to how humans have introduced nuance into our calendars and clocks. In this course, I will help you straighten it all out. You will learn about UTC, daylight saving time, time zones, and calendar systems. You will also learn how date and time values are represented and manipulated in various programming languages. We will look closely at the different kinds of time zone data, and discuss various fallacies and gotchas that are commonly encountered. We will deep dive into how date and time are handled in the .NET Framework, and in JavaScript. We will also look at various libraries that make things slightly more bearable. Throughout the course, you will learn about real-world situations that require deeper thought about how date and time are handled in your applications, and I will give you practical advice on how to solve them.

About the author
About the author

Matt Johnson programs in both C# and JavaScript, and specializes in Date and Time related issues.

Section Introduction Transcripts
Section Introduction Transcripts

Date and Time in the .NET Framework
I hope you've been enjoying the course so far. Until now, I have been showing you concepts that are generic to almost every programming language, and could be valuable to even non-programmers; however, in this module, I am going to focus on the specific details of how date and time work in the Microsoft. NET Framework. I'll use C# as the programming languages in all examples, but the features are identical in Visual Basic, and other. NET languages. Here's a very simple overview of how date and time work in. NET. There are a few built-in data types that you should learn. All of these are immutable value objects implemented as structs. In other words, they are used in the same way as simple types, like integers, and booleans. They are not classes. They are DateTime, DateTimeOffset, and TimeSpan. All three are in the System namespace in the. NET Framework's base class library. In addition to these, there are a few related classes that are relevant to any discussion about date and time. They are TimeZoneInfo from the System namespace, Calendar from the System. Globalization namespace, and Stopwatch from the System. Diagnostics namespace. Like the others, these are all included in the base class library that comes with. NET. Each of these items is for a specific purpose, and has its own quirks, so let's take a closer look at each of them individually.

Date and Time in JavaScript
In this module, I'm going to talk about some of the challenges when handling date and time issues in JavaScript. JavaScript is quickly becoming one of the most popular programming languages around. In the past, JavaScript might have been used for minor scripting tasks, like programmatically pressing buttons on a web page, but nowadays entire applications are being written using JavaScript. Frontend frameworks like Angular, Ember, and Durandal, have brought JavaScript usage to a new level in the browser, and technologies like Node. js, have brought JavaScript to the server as well. Regardless of whether you primarily program in. NET, Java, Ruby, Python, PHP, or something else, you are probably also using JavaScript. Unfortunately, when it comes to date and time, JavaScript is nowhere near as mature as other languages you might be used to. In order to be effective, and reduce risks of making errors, you need to be very careful about how you use the various language and environment features. You also need to be careful with libraries. There are some great date and time libraries, but there are some poor ones out there as well. As you have probably gathered by now, date and time is deceptively complex. Many library authors are simply not familiar with all the nuances. I'll discuss some of the better libraries later in this module.

Date and Time in Other Programming Languages
I'd now like to take you through a quick tour of date and time functionality in a handful of different programming languages. While I'm not going to cover these as in-depth as I have with. NET or JavaScript, I'd still like you to have a general idea at how things work in other languages, so you can get a feel for the similarities, and differences between them. If one of these is your primary programming platform, please consider this as a starting point. You should continue your research by reading through the documentation, and reviewing other online resources.

Common Mistakes and Best Practices
All developers make mistakes from time to time, but some mistakes are made more often than others. When it comes to date and time issues, there are a handful of mistakes that almost every developer makes at least once. In this module, I'm going to illustrate the more common ones. I'm also going to go through a few advanced scenarios that you are likely to encounter, so that you can understand the best practices for handling them. Hopefully by the end of this module, you will have all the information that you need to correctly design and implement date and time related features into your applications.