继承我的代码...
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格式的印度格式,但我的代码无效。
答案 0 :(得分:0)
只需使用
salesmodel.Date.ToString("dd/MM/yy");