如何在en.net中将日期时间的格式更改为在asp.net mvc4中的en-IND(印度时间)

时间:2013-08-14 05:11:42

标签: asp.net-mvc-4

继承我的代码...

if (ModelState.IsValid)
{
    orders.Status = "Billing Done";
    DateTime date= DateTime.ParseExact(salesmodel.Date.ToString(),                   
    "dd/MM/yyy", CultureInfo.InvariantCulture);
    var sales = new Sale
    {
        OrderId = salesmodel.OrderId,
        Date=date,
        Amount = salesmodel.Amount,
        Freight = salesmodel.Freight,
        VatTypeId = salesmodel.VatTypeId,
        VatAmount=salesmodel.VatAmount,
        TotalAmount = salesmodel.TotalAmount,
        IsActive=salesmodel.IsActive,
        Status=salesmodel.Status
    };
    context.Sales.Add(sales);
    context.SaveChanges();
    return RedirectToAction("Index");
}

return View();

它是一个控制器动作方法..我需要将datetime格式转换为dd / MM / yyyy格式的印度格式,但我的代码无效。

1 个答案:

答案 0 :(得分:0)

只需使用

salesmodel.Date.ToString("dd/MM/yy");