I'm using "yyyy-MM-dd" several time in the code for date formatting
For example :
var targetdate = Date.ToString("yyyy-MM-dd");
Is it possible to declare the format as constant, so that use of the code again and again can be avoided
Use an extension method without declare any format again and again like this:
public static class DateExtension
{
public static string ToStandardString(this DateTime value)
{
return value.ToString(
"yyyy-MM-dd",
System.Globalization.CultureInfo.InvariantCulture);
}
}
So you use it in this way
var targetdate = Date.ToStandardString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With