Header Ads

C#.NET: How to convert Date/Time to Formatted String

When working with date/time values, it is often need of the solution to provide proper date/time format for better user understanding. Asmak9.EssentialToolKit library provides many pre-defined date/time formats and a very simple method to convert date/time value into formatted string.

Today, I shall be demonstrating method of Asmak9.EssentialToolKit .NET library to convert Date/Time value into formatted String 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 "ConvertDateTimeToString".  
 
2) Open "Tools\Nuget Package Manage\Manage Nuget Packages for Solution...".

3) Install Asmak9.EssentialToolKit Nuget Package.

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

...

// Convert Date/Time to String with Formats method.
string datetime = utilityKit.ConvertDateTimeToString(dateTimeVal, datetimeFormats.DATETIME_FORMAT_9);

...

The above code will convert provided date/time value into target formatted date/time string value using pre-defined date/time formats provided by Asmak9.EssentialToolKit library. You also need to initialize 'UtilityKit' & 'DateTimeFormats' classes 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 formatted String value using C#.NET console application. You will also learn to use 'DateTimeFormats' class pre-defined date/time format value.

1 comment:

  1. Hi, your writing and sharing is very nice, I really like it. I hope many people will find it useful if they see or understand it well.

    ReplyDelete