從字符串中獲取時間並比較大小


 

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