In many cases, all you need to do is call a particular method, such as toLocaleString(), to obtain the desired result. However, sometimes you need to build a custom presentation. The two custom examples — Custom Date (m/d/y) and Custom Time (h:m:s:ms) — show how to create a custom date or custom time output using functions such as getMonth().
The example creates two date values and two time values. Each of the values actually contains both date and time. The application uses the Date object one way or the other, but that’s the application’s view of the object, rather than a determination the object has made. In fact, you can’t create a time value without also defining a date as part of it.
The example shows two techniques for creating a Date object. You can supply a string or individual values as shown. You can also create a Date object by providing the number of milliseconds since midnight, January 1, 1970.
To determine the time span, you simply subtract one value from the other. The only problem is that the output is in milliseconds and most people don’t understand milliseconds. The example shows how to convert a time span to days or minutes.