The UniTools class contains a collection of utility methods. All the exposed functionalities are under static methods, so they can be called directly from the class itself.
GetDate()
The GetDate() method convert a date into a string with the right format to be correctly recognized by the MySQL DateTime data-type. It has 2 overloads:
This method overload just returns the current date and time in the international format as specified in the optional format parameter.
This method overload returns the given date DateTime object converted in the international format as specified in the optional format parameter.
GetDateFromString
The GetDateFromString() method convert a string, containing a date and time, into a DateTime object.
The date parameter must be a string containing a date and time definition. By default, the method expects the date and time are in English format (year-month-day hours:minutes:seconds). However, you can manage other data formats by setting the optional cultureInfo parameter to a different country code.
ConvertPercentage
The ConvertPercentage() is a utility method to generates a formatted string from a value which is a percentage from 0 to 1. This method converts this value into a number between 0 to 100, with a certain numbers of decimals, and add the % symbol.
For example, if you pass 0.2, the method will return 20%.
ConvertBytes
The ConvertBytes() is a utility method that converts a certain number of bytes in a more readable string of Kilobytes, Megabytes, Gigabytes and so on, with the given number of digits (optional, default = 1).
Examples
Number of bytes | Returned string |
420 | 420 bytes |
2600 | 2.5 KB |
1258291 | 1.2 MB |