开发者

Format DateTime.Now

A peculia开发者_StackOverflow社区r request this one.

I am looking to compare two times in C#.

I have:

DateTime systemDate = DateTime.Now.AddMinutes(-15);
//which I presume subtracts 15 minutes from the current time

I am then reading in an ftp file from a Fedora server containing a date and time that I am reading in as a stream and converting to a DateTime

2011-03-17 09:00:18.000000000 +0000

I then parse this:

compareDate = DateTime.Parse(streamer);

My Question therefore is how do I format systemDate to be in the same format as the one I have parsed in compareDate? I am aware you can format DateTime but all of the sites I have seen so far dont have it in this format.

Thank you in advance, feel free to comment if you think I have missed anything :)


You can do it like this,

DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");


No need to format systemDate, because you already parsed the date from the FTP server into a DateTime. You can just compare systemDate with compareDate.


just use var systemDate = DateTime.UtcNow.AddMinutes(-15); for your original one, then you just

if (DateTime.Equals(systemDate, compareDate))
{
    //...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜