0

这是我的代码...

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();

它是一种控制器操作方法。我需要将日期时间格式转换为 dd/MM/yyyy 格式的印度格式,但我的代码不起作用。

4

1 回答 1

0

只需使用

salesmodel.Date.ToString("dd/MM/yy");
于 2013-08-14T05:23:42.417 回答