解决方案 »
- (asp.net前端处理)保存刷新先前的输入值
- winform datagridview 删除行
- 求一个工具能够控制端口访问
- C#如何正确调用 c++的字符数组?确实没有分数了,跪求解决!
- 水晶报表的一个棘手的问题:多页的时候会在每个页面下面多出一行,请问什么原因?
- 如果要下载lkk2073提供的OA系统或要提高,请来这里
- 菜!WebForm中怎么做报表打印
- 谁写过类似{$PageNav$}这种的标签,帮忙看看!!
- 怎样在ComboList的每一个Item中增加一个Tag属性?
- 要取得应用程序所在目录的绝对地址,该怎么写????
- 高分求解:在服务管理器里面启动服务进程和手工双击exe启动进程的区别
- datagridview中combobox的SelectedIndexChanged事件函数问题
如果长度不固定,没办法,转换不了
1.如果月、日是个位数(如1号到9号,1月到9月),则转换后只显示1至9,而不是01至09;
2.如果小时也是个位,则转换后只显示1至9,而不是01至09;
3.分、秒能显示十位的0;
static void Main(string[] args)
{
string str = @"2015/01/03 04:02:01";
DateTime dt = DateTime.Parse(str);
//DateTime dt = DateTime.Now;
Console.WriteLine("#######");
Console.WriteLine(dt);
Console.ReadKey();
}
所以,上述输出是:2015/1/3 4:02:01
你在网上搜C# datetime,有个cnbolg把这个的用法讲的很详细,你自己看吧。我也不懂。
http://www.cnblogs.com/ymyglhb/archive/2009/04/22/1441293.html
代码string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
代码string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
不对啊...
而不是你给的那种字符串...哪吒给你的代码都已经是DateTime了,想要什么格式随便你了啊
string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
return dt.ToString("yyyy-MM-dd HH:mm:ss");
代码string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
不对啊...
注意我给的代码,复制过去用,不要自己瞎改
而不是你给的那种字符串...哪吒给你的代码都已经是DateTime了,想要什么格式随便你了啊
string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
return dt.ToString("yyyy-MM-dd HH:mm:ss");
我逗了,老想着不去NEW东西然后进行转换的...
结贴答案:
string s = "20150113144244";
DateTime.ParseExact(s, "yyyyMMddHHmmss", null).ToString("yyyy-MM-dd HH:mm:ss")
代码string s = "20150113144244";
DateTime dt = DateTime.ParseExact(s, "yyyyMMddHHmmss", null);
不对啊...
注意我给的代码,复制过去用,不要自己瞎改
问题解决了,谢谢,我把你的代码改成
string s = "20150113144244";
DateTime.ParseExact(s, "yyyyMMddHHmmss", null).ToString("yyyy-MM-dd HH:mm:ss")
private void btn_Convert_Click(object sender, EventArgs e)
{
#region 针对Windows 7系统
string s = string.Format("{0}/{1}/{2}",//得到日期字符串
txt_Year.Text, txt_Month.Text, txt_Day.Text);
DateTime P_dt = DateTime.ParseExact(//将字符串转换为日期格式
s, "yyyy/MM/dd", null);
#endregion
//#region 针对Windows XP或者2003系统
//string s = string.Format("{0}{1}{2}",//得到日期字符串
// txt_Year.Text, txt_Month.Text, txt_Day.Text);
//DateTime P_dt = DateTime.ParseExact(//将字符串转换为日期格式
// s, "yyyyMMdd", null);
//#endregion
MessageBox.Show("输入的日期为: "//弹出消息对话框
+ P_dt.ToLongDateString(), "提示!");
}