DATETIME BYTE数组
来源:互联网 发布:sql sever 数据挖掘 编辑:程序博客网 时间:2024/06/11 23:12
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bytex(7) As Byte
bytex(0) = 0
bytex(1) = 0
bytex(2) = 0
bytex(3) = 0
bytex(4) = 96
bytex(5) = 110
bytex(6) = 227
bytex(7) = 64
Dim dtx As Date
'Dim ss As String
'Dim year As Integer = bytex(7)
'Dim month As Integer = bytex(6)
'Dim day As Integer = bytex(5)
'Dim c1 As System.Globalization.Calendar = New System.Globalization.GregorianCalendar
'dtx = c1.ToDateTime(year, month, day, 0, 0, 0, 0, 0)
''ss = System.BitConverter.ToString(bytex, 0)
''ss = Strings.Replace(ss, "-", "")
''ss = Strings.StrReverse(ss)
''dtx = aaax(bytex())
dtx = GetDateFromBytes(bytex)
' 解决!()
' byte[] hexString = new byte[] { 0xA0, 0xE9, 0x88, 0x7D, 0xC7, 0x56, 0x00, 0x40 }; //1900-1-1 1:1:1
' long tickBase = DateTime.Parse( "1899-12-30 0:0:0 ").Ticks; //delphi基础日期在c#中的位置
' double doub = Math.Abs( BitConverter.ToDouble(hexString, 0));//该字节数组代表的基于delphi基础日期的偏移值
' long tickAddition = (long)(doub * 10000000 * 3600 * 24);//;将该偏移值转换为c#表示形式。(doub*1天的总毫微秒)delphi的小数部分表示时间,整数部分表示日期,所以这样处理
' DateTime objDt = new DateTime(tickBase + tickAddition);//转换为日期
'谢谢各位。ruan_hg(阿阮)ParadiseX(夜.夜.夜.夜)Red_angelX(八戒)wsxqaz(原来可以改昵称)
'/// <summary>
' /// 将DATETIME类型的对象转为可用的BYTE数组
' /// </summary>
' /// <param name="dt"></param>
' /// <returns></returns>
' private byte[] DateTimeToBytes(DateTime dt)
' {
' byte[] bytes = new byte[6];
' if (dt != null)
' {
' bytes[0] = Convert.ToByte(dt.Year.ToString().Substring(2, 2),16);
' bytes[1] = Convert.ToByte(dt.Month.ToString(), 16);
' bytes[2] = Convert.ToByte(dt.Day.ToString(), 16);
' bytes[3] = Convert.ToByte(dt.Hour.ToString(), 16);
' bytes[4] = Convert.ToByte(dt.Minute.ToString(), 16);
' bytes[5] = Convert.ToByte(((int)dt.DayOfWeek).ToString(), 16);
' //bytes[5] = 0xA;
' //bytes[5] = Convert.ToByte(dt.Second.ToString(), 10);
' }
' return bytes;
' }
'/// <summary>
' /// 将BYTE数组转换为DATETIME类型
' /// </summary>
' /// <param name="bytes"></param>
' /// <returns></returns>
' private DateTime BytesToDateTime(byte[] bytes)
' {
' if (bytes != null && bytes.Length >= 5)
' {
' int year = 2000 + Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[0] }, 0));
' int month = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[1] }, 0));
' int date = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[2] }, 0));
' int hour = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[3] }, 0));
' int minute = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[4] }, 0));
' DateTime dt = new DateTime(year, month, date, hour, minute, 0);
' return dt;
' }
' Else
' {
' return new DateTime();
' }
' }
End Sub
Public Function GetDateFromBytes(ByRef arr() As Byte) As Date
Dim tickBase, tickAddition As Long
Dim doub As Double
Dim dt As Date
tickBase = DateTime.Parse("1899-12-30 0:0:0 ").Ticks
doub = Math.Abs(System.BitConverter.ToDouble(arr, 0))
tickAddition = CLng(doub * 10000000 * 3600 * 24)
dt = New Date(tickBase + tickAddition)
Return dt
End Function
End Class
- DATETIME BYTE数组
- C#中将DateTime类型转换成Byte数组
- C#中将Byte数组转化成DateTime类型
- byte与datetime的转化
- byte和byte数组
- byte数组
- Datetime 和多维数组
- C#byte数组合并
- 文件和byte数组
- 合并byte[]字节数组
- CBITMAP转为BYTE数组
- C# byte 数组合并
- c# 合并byte数组
- C# byte[]数组,问答
- Byte 数组 转 DataHandler
- 合并byte数组
- byte[]数组合并
- Java的byte数组
- java中HashMap遍历方法
- Java中的同步与互斥机制--synchornized学习
- POSIX线程同步
- 线性表
- htmlparser使用的一点体会
- DATETIME BYTE数组
- 关于Delphi
- HtmlParser例程和实例结果
- HTMLParser
- 使用 ncache 搭建快速的 web 缓存服务器
- Source Insight 快速注释选中内容
- 知道ReactOS是什么吗?
- Oracle Trigger
- 关于证书文件ie中不能下载的问题