2010-05-29 20 views
1

我需要将脚本任务SSIS中的系统日期时间转换为时间戳。C#中的时间戳

输入日期格式:29/05/2010上午02点36

输出格式:29-15-2010 14时36分00秒

感谢 prav

回答

1

输出不与输入非常匹配(月份变为15,并且从AM到PM)。我认为那些是错别字。它应该是这样的:

string output = DateTime.ParseExact(input, "dd/MM/yyyy h:m tt", null).ToString("dd-MM-yyyy HH:mm:ss"); 

如果是用户输入,你可能需要TryParseExact来代替。

1

Givig输出到字符串方法的格式给出时间戳结果。字符串dt = DateTime.Now.ToString(“yyyy' - 'MM' - 'dd''HH':'mm':'ss”);

 DateTime dateformat = Convert.ToDateTime(dt); 
     Console.WriteLine(dt); 
     Console.WriteLine(dateformat); 
     Console.ReadLine(); 

感谢 prav

0
 DateTime.Parse(input).ToString("dd-MM-yyyy HH:mm:ss")