转换格式

yyantifa 2012-05-17 04:45:53
string time="2012-05-17 20:00:30";
如何将字符串转为:20120517200030
...全文
110 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengzq 2012-05-17
  • 打赏
  • 举报
回复
除了楼上的,哥来提供第3种方法,使用正则表达式:

static void Main(string[] args)
{
string time = "2012-05-17 20:00:30";
Console.WriteLine(time);
time=System.Text.RegularExpressions.Regex.Replace(time,@"[^\d]","");
Console.WriteLine(time);
Console.ReadKey();

}
stonespace 2012-05-17
  • 打赏
  • 举报
回复
string time="2012-05-17 20:00:30";
string strResult=time.Replace("-",null);
strResult=strResult.Replace(" ",null);
strResult=strResult.Replace(":",null);
山之魂2 2012-05-17
  • 打赏
  • 举报
回复
 string  time="2012-05-17 20:00:30";
DateTime dt = Convert.ToDateTime(time);
time = dt.ToString("YYYYMMDDHHmmSS");
孟子E章 2012-05-17
  • 打赏
  • 举报
回复
string time = "2012-05-17 20:00:30";
DateTime a = DateTime.ParseExact(time, "yyyy-MM-dd HH:mm:ss",null);
MessageBox.Show(a.ToString("yyyyMMddHHmmss"));
yyantifa 2012-05-17
  • 打赏
  • 举报
回复
这个可以怎么转呀

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧