Applies to: Nevron Chart for .NET
How to use the built-in Date/Time units?
Nevron Chart has support for operations on date/time values which extend the built-in DateTime and TimeSpan classes included in the .NET framework. This topic will teach you how you can use built-in support for date / time operations for your own purposes.
Date Time Units - Date/time units are units measuring time. In Nevron Chart there are two general classes of units – absolute and relative:
- Absolute units are units that always have a fixed representation in ticks (the smallest date time unit). An example of such units are milliseconds, seconds, hours, days and weeks.
- Relative units on the other hand do not have a fixed representation because they may vary depending on the reference date. For example the month is a relative unit because it may contain between 28 to 31 days depending on the date.
All date time units implement the Add method which allows you to move forward or backwards from a certain reference date. The following code snippet for example will add one day to the current date:
[C#]
DateTime today = DateTime.Now;
DateTime tomorrow = NDateTimeUnit.Day.Add(today, 1);
Similarly:
DateTime today = DateTime.Now;
DateTime yesterday = NDateTimeUnit.Day.Add(today, -1);
[VB.NET]
Dim
today
As
DateTime = DateTime.Now
Dim
tomorrow
As
DateTime = NDateTimeUnit.Day.Add(today, 1)
Similarly:
Dim
today
As
DateTime = DateTime.Now
Dim
yesterday
As
DateTime = NDateTimeUnit.Day.Add(today, -1)
Date Time Span - NDateTimeSpan class groups together a date time unit and number and adds a few useful methods that you can use to work with date times:
[C#]
DateTime now = DateTime.Now;
NDateTimeSpan span =
new
NDateTimeSpan(1, NDateTimeUnit.Week);
DateTime twoWeekAfterNow = span.AddMultiplied(now, 2);
Or:
DateTime now = DateTime.Now;
NDateTimeSpan span =
new
NDateTimeSpan(1, NDateTimeUnit.Week);
DateTime twoWeekBeforeNow = span.SusbstractMultiplied(now, 2);
[VB.NET]
Dim
now
As
DateTime = DateTime.Now
Dim
span
As
New
NDateTimeSpan(1, NDateTimeUnit.Week)
Dim
twoWeekAfterNow
As
DateTime = span.AddMultiplied(now, 2)
Or:
Dim
now
As
DateTime = DateTime.Now
Dim
span
As
New
NDateTimeSpan(1, NDateTimeUnit.Week)
Dim
twoWeekBeforeNow
As
DateTime = span.SusbstractMultiplied(now, 2)
With the help of Date Time Units and the Date Time Span you can work with absolute and relative units seamlessly.
Article ID: 54, Created On: 10/6/2010, Modified: 11/15/2010