[英]Convert ShortTime string to DateTime format
DateTime time = DateTime.Now;
string newTime = time.ToShortTime();
如何將此newTime字符串轉換為DateTime格式
請嘗試使用以下代碼段。
DateTime time = DateTime.Now;
string newTime = time.ToShortTimeString();
DateTime dt = new DateTime();
DateTime.TryParse(newTime,out dt);
注意:它將設置當前日期。
最后我找到了答案
const string FMT = "O";
DateTime now1 = DateTime.Now;
string strDate = now1.ToString(FMT);
DateTime now2 = DateTime.ParseExact(strDate, FMT, CultureInfo.InvariantCulture);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.