簡體   English   中英

在C#中格式化日期時出現問題

[英]Issue while formatting date in c#

我將TextBox DateTime值傳遞給api中的實體模型,並將datetime格式化為CultureInfo(“ en-GB”,true),同時將數據保存到數據庫中。

它以天為月份,以月為日期。

這是我的代碼:

IFormatProvider FormatDate = new System.Globalization.CultureInfo("en-GB", true);

Convert.ToDateTime(user.DOB, FormatDate);

我將通過dd-MM-yyyy格式的日期“ 08-04-2019”傳遞到user.DOB中。

user.DOB顯示Day = 4和Month = 8您可以在下圖中檢查它...

日期時間值

我解決了我的問題

轉換public DateTime DOB { get; set; } public DateTime DOB { get; set; } public DateTime DOB { get; set; } public string DOB { get; set; } public string DOB { get; set; } public string DOB { get; set; }在DTO中

然后將其轉換為帶有en-GB格式的DateTime,同時進入保存過程

IFormatProvider FormatDate = new System.Globalization.CultureInfo("en-GB", true);

Convert.ToDateTime(user.DOB, FormatDate);

您也可以這樣做。

var mydate = new DateTime(1976, 10, 13);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM