如何HEX数据转换为datetime [英] How to convert HEX data to Datetime

查看:114
本文介绍了如何HEX数据转换为datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样529CD17C.This一个十六进制字符串对应于一个日期时间2013年12月2日下午6点29分16秒(即MM / DD / YYYY HH:MM:SS AM / PM)。。如何我能做到这一点在C#代码

I have a hex string like this 529CD17C.This is corresponding to One date time 12/2/2013 06:29:16 PM .(ie in MM/dd/yyyy hh:mm:ss AM/PM).How can i do this in c# coding

推荐答案

您正在使用UNIX时间戳工作。首先,你需要将其转换为整数值,然后继续前进,几秒钟的量添加到时代(1970年1月1日)

You are working with a UNIX time stamp. First you need to convert it to an integer value, then go ahead and add that amount of seconds to the epoch (January 1, 1970).

下面是一个例子:

string hexValue = "529CD17C";
int secondsAfterEpoch = Int32.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
DateTime epoch = new DateTime(1970, 1, 1);
DateTime myDateTime = epoch.AddSeconds(secondsAfterEpoch);
Console.WriteLine(myDateTime);



希望这是有帮助!

Hope that was helpful!

这篇关于如何HEX数据转换为datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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