How can I get today's date in M/d/yyyy
format irrespective of system format of date using C#?
DateTime.Now.Tostring('M/d/yyyy')
is working only if the system date is in format dd/MM/yyyy
or M/dd/yyyy
but is not working in case yyyy-MM-dd
format.
Eg:
if system date is 2013-06-26
then DateTime.Now.Tostring('M/d/yyyy')
is converting the date into 06-26-2013
but not in 06/26/2013
Use CultureInfo.InvariantCulture
to enforce /
as date separator:
DateTime.Now.ToString("M/d/yyyy", CultureInfo.InvariantCulture)
Ideone
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