C# .net Datetime to Integer value

2020-03-24 05:36发布

I am really new to C# and I am having problem in converting DateTime to it's Integer date format. I have search already the net but I did not find my answer.

I want is to convert the current Date to integer. Example the date "2011-08-11" in format "yyyy-MM-dd" has an integer value of 734360

标签: c# datetime
4条回答
The star\"
2楼-- · 2020-03-24 06:18
int calculation;
DateTime processDate;
calculation = Convert.ToInt32(Convert.ToString(processDate));

u can also use this way.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-03-24 06:35

Pervasive uses days since 1/1/1.

To convert from int to a date use

new DateTime(1, 1, 1).AddDays(734360)

To convert to an int from a date use

TimeSpan t = (new DateTime(2011, 08, 11)-new DateTime(1, 1, 1));
int days = (int)t.TotalDays+1;
查看更多
够拽才男人
4楼-- · 2020-03-24 06:36

You can try this too:

DateTime MyDate = new DateTime(); 

int Year = MyDate.Year;
int Month = MyDate.Month;
int Day = MyDate.Day;

if it is what you're looking for.

查看更多
走好不送
5楼-- · 2020-03-24 06:42

myDateTime.Ticks will give you a uniquely representative Int64 value if that is what you need.

查看更多
登录 后发表回答