从字符串中获取时间并比较大小


 

using System; 
namespace StringApplication 
{
class StringProg 
{ 
static void Main(string[] args) 
{ 
string str = "2018-08-07 09:50"; 
Console.WriteLine(str); 
string substr = str.Substring(10); 
string str2="10:30";
Console.WriteLine(substr); 
Console.WriteLine("compare "+substr+" with "+str2);
DateTime dt1=Convert.ToDateTime(substr);
DateTime dt2=Convert.ToDateTime(str2);
if(DateTime.Compare(dt1,dt2)>0)    
Console.WriteLine(substr+" later than "+str2);    
else
Console.WriteLine(substr+" earlier "+str2);    
Console.ReadKey() ; 
} 
} 
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM