DateTime.ToOADate-仅时间 [英] DateTime.ToOADate - Time only

查看:51
本文介绍了DateTime.ToOADate-仅时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有当前日期(DateTime.Now)的"DateTime"变量.我可以将其转换为OADate格式(41392,524432),例如.但是,我该如何转换,我只是获得没有日期的时间?例如,这种格式的1分4秒(01:04)是0,04444444.

I have a "DateTime" var with the current date (DateTime.Now). I can convert this to a OADate-Format (41392,524432) as example. But how I can convert this, that I'm just getting the time without the date? For example 1 minute and 4 seconds (01:04) are 0,04444444 in this format.

推荐答案

OLE自动化日期被实现为浮点数,其整数部分是1899年12月30日午夜之前或之后的天数.

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899

您可能想将其用作基准日期:

you presumably want to use that as your base date:

DateTime oaBaseDate = new DateTime(1899,12,30);
double result = oaBaseDate.Add(DateTime.Now.TimeOfDay).ToOADate();

或者如果您不喜欢魔术数字(魔术日期),则等效:

or if you don't like magic numbers (magic dates), the equivalent:

DateTime oaBaseDate = DateTime.FromOADate(0);
double result = oaBaseDate.Add(DateTime.Now.TimeOfDay).ToOADate();

这篇关于DateTime.ToOADate-仅时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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