I want my datetime to 开发者_Python百科be converted to a string that is in format "dd/MM/yyyy"
Whenever I convert it using DateTime.ToString("dd/MM/yyyy")
, I get dd-MM-yyyy
instead.
Is there some sort of culture info that I have to set?
Slash is a date delimiter, so that will use the current culture date delimiter.
If you want to hard-code it to always use slash, you can do something like this:
DateTime.ToString("dd'/'MM'/'yyyy")
Pass CultureInfo.InvariantCulture as the second parameter of DateTime, it will return the string as what you want, even a very special format:
DateTime.Now.ToString("dd|MM|yyyy", CultureInfo.InvariantCulture)
will return: 28|02|2014
Add CultureInfo.InvariantCulture
as an argument:
using System.Globalization;
...
var dateTime = new DateTime(2016,8,16);
dateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
Will return:
"16/08/2016"
If you use MVC, tables, it works like this:
<td>@(((DateTime)detalle.fec).ToString("dd'/'MM'/'yyyy"))</td>
Try this.
@foreach (DataRow _Row in CashBook2.Rows)
{
<tr>
<td>@DateTime.Parse(_Row["Vou_Date"].ToString()).ToString(DateFormat)</td>
<td>@_Row["Vou_No"].ToString()</td>
<td>@_Row["Description"].ToString()</td>
<td>@decimal.Parse(_Row["DR"].ToString()).ToString(NumFormat)</td>
<td>@decimal.Parse(_Row["CR"].ToString()).ToString(NumFormat)</td>
<td>@Balance</td>
</tr>
}
Dumb question/answer perhaps, but have you tried dd/MM/yyyy
? Note the capitalization.
mm
is for minutes with a leading zero. So I doubt that's what you want.
This may be helpful: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm
精彩评论