从DATETIME转换为格式(“{0:dd,MMMM,yyyy}” [英] convert from DATETIME to Format("{0:dd, MMMM, yyyy} from
本文介绍了从DATETIME转换为格式(“{0:dd,MMMM,yyyy}”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 gridview 中选择后从 DATETIME 转换时出现问题。
请更正以下代码
Having problem converting from DATETIME after selecting from gridview.
Please correct the codes below
var dt = SqlCmd.Parameters["@ZESTABLISH"].Value.ToString();
txt_Establish.Text = String.Format("{0:dd, MMMM, yyyy}", dt);
推荐答案
尝试这样的事情......
Try something like this...
DateTime_Value.ToString("dd-MMM-yyyy");
有关DateTime到字符串转换的更多信息...
< a href =http://www.codeproject.com/Articles/19677/Formats-for-DateTime-ToString> DateTime.ToString()的格式 - Codeproject文章 [ ^ ]
DateTime.ToString() - MSDN [ ^ ]
首先你需要将日期从字符串转换为DateTime类型,然后你可以将它转换为你的字符串表示ant。
First you need to convert the date from a string into a DateTime type, then you can convert it to the string representation you want.
string dateString = SqlCmd.Parameters["@ZESTABLISH"].Value.ToString();
string currentFormat = "MM/dd/yyyy"; // No idea what your current format is.
DateTime dt = DateTime.ParseExact(dateString, currentFormat, null);
txt_Establish.Text = dt.ToString("dd, MMMM, yyyy"); // Or whatever format you want
您的dt
必须dateTime
Yourdt
must bedateTime
DateTime dt = DateTime.Parse(System.DateTime.Now.ToString());
String dates = String.Format("{0:dd, MMM, yyyy}", dt);
参考:
http://www.csharp-examples.net/string-format-datetime/ [ ^ ]
这篇关于从DATETIME转换为格式(“{0:dd,MMMM,yyyy}”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文