Header Ads

C#.NET: How to convert Date/Time to TimeSpan Format

For performing time related processing, Date/Time format value is often converted to TimeSpan format. Asmak9.EssentialToolKit library provides a method to convert date/time value into TimeSpan format value.

Today, I shall be demonstrating method of Asmak9.EssentialToolKit .NET library to convert Date/Time value into TimeSpan format value using C#.NET console application.
 

Prerequisites:

Following are some prerequisites before you proceed any further in this tutorial:
  1. Install Asmak9.EssentialToolKit Nuget Package.
  2. Knowledge of Nuget Package Manager.
  3. Knowledge of C# Programming.
The example code is being developed in Microsoft Visual Studio 2019 Professional. 

Download Now!

Let's begin now.

1) Create new C#.NET console application and name it "ConvertDateTimeToTimeSpan".
  
2) Open "Tools\Nuget Package Manage\Manage Nuget Packages for Solution...".

3) Install Asmak9.EssentialToolKit Nuget Package.

4) Now, create "ConvertDateTimeToTimeSpan.cs" file and type following lines of code i.e.

...

// Convert Date/Time to Time Span method.
TimeSpan timespan1 = utilityKit.ConvertDateTimeToTimeSpan(dateTime1);

...

The above code will convert provided date/time value into time span. You also need to initialize 'UtilityKit' class with or without your license key.

5) Now, execute the project and you will be able to see the following i.e.


Conclusion

In this article, you will learn about the method of Asmak9.EssentialToolKit .NET library to convert Date/Time value into TimeSpan format value using C#.NET console application.

1 comment:

  1. Thanks for this great post. Blogging is a very intricate world for beginners.
    Home Tutor in Rawalpindi

    ReplyDelete