将数字字符串(hh.mm.ss)转换为秒的最佳方法是什么?我使用visual studio,所以C#。
//I receive the data in this format hh.mm.ss and I store it in "time"
String time;
...
//hh.mm.ss to ss
time = time.Replace(".", "");
//how can I proceed?
int numTime = Int64.Parse(time);
答案 0 :(得分:0)
您可以将字符串提供给日期时间对象,如此
string dateString = "24.12.03";
DateTime dateObject = DateTime.ParseExact(dateString, "hh.mm.ss",System.Globalization.CultureInfo.InvariantCulture);
然后你可以简单地拉出像这样的秒数
Console.WriteLine(dateObject.Seconds);