热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

需要帮助将Delphi时间转换为.Net时间-NeedHelptoConvertingDelphiTimeto.NetTime

IamportingaDelphiapplicationtoC#andIverunintoaproblem.TheDelphiapprecordsthetime

I am porting a Delphi application to C# and I've run into a problem. The Delphi app records the time into a log file, which then gets read back into the program. But the format of the time it records confuses me. I can find no .Net library to convert it properly.

我正在将一个Delphi应用程序移植到C#,我遇到了一个问题。 Delphi应用程序将时间记录到日志文件中,然后将其读回程序。但它记录的时间格式让我困惑。我找不到.Net库来正确转换它。

Delphi recorded time in log file: 976129709 (this gets converted to 1/14/2009 5:53:26 PM in the Delphi code)

Delphi在日志文件中记录时间:976129709(在Delphi代码中将其转换为1/14/2009 5:53:26 PM)

//Here is the Delphi code which records it: 
IntToStr(DirInfo.Time);

//Here is the Delphi code which reads it back in:
DateTimeToStr(FileDateToDateTime(StrToInt(stringTime));

Anybody have any ideas how I can read this in .Net?

任何人都有任何想法,我怎么能在.Net中读到这个?

3 个解决方案

#1


Delphi's TSearchRec.Time format is the old DOS 32-bit date/time value. As far as I know there's no built-in converter for it, so you'll have to write one. For example:

Delphi的TSearchRec.Time格式是旧的DOS 32位日期/时间值。据我所知,它没有内置转换器,所以你必须写一个。例如:

public static DateTime DosDateToDateTime(int DosDate)
{
     Int16 Hi = (Int16)((DosDate & 0xFFFF0000) >> 16);
     Int16 Lo = (Int16)(DosDate & 0x0000FFFF);

     return new DateTime(((Hi & 0x3F00) >> 9) + 1980, (Hi & 0xE0) >> 5, Hi & 0x1F,
        (Lo & 0xF800) >> 11, (Lo & 0x7E0) >> 5, (Lo & 0x1F) * 2);
}

#2


Here is description of different date/time formats (Delphi's native TDateTime is OLE Automation date format). According to this, you need System.DateTime.FromFileTime() and System.DateTime.ToFileTime() + DosDateTimeToFileTime() and FileTimeToDosDateTime() functions. Actually, this is conversion in two-steps.

以下是不同日期/时间格式的描述(Delphi的本机TDateTime是OLE自动化日期格式)。根据这个,你需要System.DateTime.FromFileTime()和System.DateTime.ToFileTime()+ DosDateTimeToFileTime()和FileTimeToDosDateTime()函数。实际上,这是两步转换。

#3


I've tried both googling and experimenting, starting with dummy code to find something similar to the unix epoch.

我尝试了谷歌搜索和实验,从虚拟代码开始,找到类似于unix时代的东西。

  var x = 976129709;
  var target = new DateTime(2009, 1, 14, 17, 53, 26);
  var testTicks = target.AddTicks(-x);     // 2009-01-14 17:51:48
  var testMs = target.AddMilliseconds(-x); // 2009-01-03 10:44:36
  var testS = target.AddSeconds(-x);       // 1978-02-08 22:44:57
  // No need to check for bigger time units
  // since your input indicates second precision.

Could you verify that your input is correct?

你能证实你的输入是正确的吗?

And for the love of the Flying Spaghetti Monster, abandon your 12 hour time format! ;)

而对于Flying Spaghetti Monster的爱,放弃你的12小时时间格式! ;)


推荐阅读
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • vue使用
    关键词: ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • 本文介绍了在CentOS 6.4系统中更新源地址的方法,包括备份现有源文件、下载163源、修改文件名、更新列表和系统,并提供了相应的命令。 ... [详细]
  • 恶意软件分析的最佳编程语言及其应用
    本文介绍了学习恶意软件分析和逆向工程领域时最适合的编程语言,并重点讨论了Python的优点。Python是一种解释型、多用途的语言,具有可读性高、可快速开发、易于学习的特点。作者分享了在本地恶意软件分析中使用Python的经验,包括快速复制恶意软件组件以更好地理解其工作。此外,作者还提到了Python的跨平台优势,使得在不同操作系统上运行代码变得更加方便。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 本文介绍了PE文件结构中的导出表的解析方法,包括获取区段头表、遍历查找所在的区段等步骤。通过该方法可以准确地解析PE文件中的导出表信息。 ... [详细]
  • Html5-Canvas实现简易的抽奖转盘效果
    本文介绍了如何使用Html5和Canvas标签来实现简易的抽奖转盘效果,同时使用了jQueryRotate.js旋转插件。文章中给出了主要的html和css代码,并展示了实现的基本效果。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
author-avatar
叶子已经不是木头的了
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有