C#.NET日期时间为整型值 [英] C# .net Datetime to Integer value

查看:100
本文介绍了C#.NET日期时间为整型值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很新的C#和我的日期时间转换为它有问题的整数日期格式。我已经搜索网,但我没有找到我的答案。



我要的是当前日期转换为整型。
实例格式YYYY-MM-DD日期2011-08-11有734360


解决方案

普及使用日以来1/1/1。



要从INT转换为日期使用

 新日期时间(1,1,1).AddDays(734360)

要转换到从日期使用int

 时间跨度T =(新的DateTime(2011,08,11) -new日期时间(1,1,1)); 
INT天数=(int)的t.TotalDays + 1;


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

解决方案

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;

这篇关于C#.NET日期时间为整型值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆