怎么把时间转成16进制 2009-12-19 13:55:11 转成 4B 2C 6A BF 4B 2C CD 2F 转成 2009-12-19 20:55:11就是互转. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 时间是8个字节long类型使用TICK属性。然后把这个TICK按照十六进制格式输出就可以了。 byte[] b = { 0x4b, 0x2c, 0xcd, 0x2f, 0, 0, 0, 0 };DateTime dt = DateTime.FromBinary(BitConverter.ToInt64(b, 0)); public static string ConvertToHex(struing str, bool reverse){ byte[] arrByte=System.Text.Encoding.Default.GetBytes(str); StringBuilder sb = new StringBuilder(); if (reverse) Array.Reverse(arrByte); foreach (byte b in arrByte) sb.AppendFormat("{0:x2}", b); return sb.ToString();} DateTime DT = DateTime.Parse("2009-12-19 13:55:11"); double D = DT.ToOADate(); Byte[] Bytes = BitConverter.GetBytes(D); String S = BitConverter.ToString(Bytes); MessageBox.Show(S); //2D-E3-43-8F-D2-9C-E3-40 DateTime t = DateTime.Parse("1970-1-1"); DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime(); DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime(); double t3 = (DateTime.Now - t).TotalSeconds; 怎么转回 时间?Convert.ToString((int)t3, 16)这样好像错了 那吧时间转换成string呢? Byte[] Bytes = BitConverter.GetBytes(t3); DateTime t= DateTime.Parse("1970-1-1"); DateTime t1= t.AddSeconds(0x4B2CCD2F).ToLocalTime(); DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime();//double t3= (DateTime.Now- t).TotalSeconds; double t3= (t1- t).TotalSeconds; Byte[] Bytes = BitConverter.GetBytes(t3); 0000C06B4FCBD241还是不会......... long t4 = (long)t3;byte[] bs = BitConverter.GetBytes(t4); byte[] bs = BitConverter.GetBytes(System.Net.IPAddress.NetworkToHostOrder(t4)); 唉DateTime t = DateTime.Parse("1970-1-1"); DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime(); DateTime t2 = t.AddSeconds(0x4B2C6ABF).ToLocalTime(); double t3 = (t1 - t).TotalSeconds; long t4 = (long)t3; byte[] bs = BitConverter.GetBytes(System.Net.IPAddress.NetworkToHostOrder(t4)); string s1 = BitConverter.ToString(bs); 这是UNIX时间戳...答案已经有了... 得出的是00-00-00-00-4B-2D-3D-AF我想要的是原来这个啊0x4B2CCD2F DateTime dt = DateTime.Parse("2009-12-19 13:55:11");string s = ((dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString("x");Console.WriteLine(s);//out:4b2c6abf using System;using System.Collections.Generic;using System.Text;namespace WWFramework.DateTimes{ /// <summary> /// 时间相关函数 /// </summary> public static class Function { /// <summary> /// 将Unix时间戳转换为DateTime类型时间 /// </summary> /// <param name="d">double 型数字</param> /// <returns>DateTime</returns> public static System.DateTime ConvertIntDateTime(double d) { System.DateTime time = System.DateTime.MinValue; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); time = startTime.AddSeconds(d); return time; } /// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="time">时间</param> /// <returns>double</returns> public static double ConvertDateTimeInt(System.DateTime time) { double intResult = 0; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); intResult = (time - startTime).TotalSeconds; return intResult; } }} 谢谢楼上的各位由其是 soaringbird 呵呵真的非常感谢原来那个时间 是 1970 1 1 8 得加个小时 关于BS或 CS的开发方式选择 webbrowser如何获取JS浮动层的源码? 求救c#中导出Excel的问题~~! 在线等待:如何把DataGrid中数据导出到Excel中(不是通过DataTable),谢谢! C#网络编程 求助 我在书上看见了toolbar控件 可是在2005中没有找到 请问该怎么使用 取连续数组 总出现的一个错误,望指教! 如何在datagrid中选中一列后,获取列中的数据.(win) 有关函数(高手请进!) 谁知道Infragistics NetAdvantage2008 Vol3 支不支持window7吗 C#如何连接odb数据库
使用TICK属性。
然后把这个TICK按照十六进制格式输出就可以了。
DateTime dt = DateTime.FromBinary(BitConverter.ToInt64(b, 0));
{
byte[] arrByte=System.Text.Encoding.Default.GetBytes(str);
StringBuilder sb = new StringBuilder();
if (reverse)
Array.Reverse(arrByte);
foreach (byte b in arrByte)
sb.AppendFormat("{0:x2}", b);
return sb.ToString();
}
DateTime DT = DateTime.Parse("2009-12-19 13:55:11");
double D = DT.ToOADate();
Byte[] Bytes = BitConverter.GetBytes(D);
String S = BitConverter.ToString(Bytes);
MessageBox.Show(S); //2D-E3-43-8F-D2-9C-E3-40
DateTime t = DateTime.Parse("1970-1-1");
DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime();
DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime();
double t3 = (DateTime.Now - t).TotalSeconds;
怎么转回 时间?
Convert.ToString((int)t3, 16)这样好像错了
Byte[] Bytes = BitConverter.GetBytes(t3);
DateTime t1= t.AddSeconds(0x4B2CCD2F).ToLocalTime();
DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime();
//double t3= (DateTime.Now- t).TotalSeconds;
double t3= (t1- t).TotalSeconds; Byte[] Bytes = BitConverter.GetBytes(t3);
0000C06B4FCBD241还是不会.........
long t4 = (long)t3;
byte[] bs = BitConverter.GetBytes(t4);
DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime();
DateTime t2 = t.AddSeconds(0x4B2C6ABF).ToLocalTime(); double t3 = (t1 - t).TotalSeconds;
long t4 = (long)t3;
byte[] bs = BitConverter.GetBytes(System.Net.IPAddress.NetworkToHostOrder(t4));
string s1 = BitConverter.ToString(bs);
得出的是
00-00-00-00-4B-2D-3D-AF我想要的是原来这个啊
0x4B2CCD2F
DateTime dt = DateTime.Parse("2009-12-19 13:55:11");
string s = ((dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString("x");
Console.WriteLine(s);
//out:4b2c6abf
using System.Collections.Generic;
using System.Text;namespace WWFramework.DateTimes
{
/// <summary>
/// 时间相关函数
/// </summary>
public static class Function
{
/// <summary>
/// 将Unix时间戳转换为DateTime类型时间
/// </summary>
/// <param name="d">double 型数字</param>
/// <returns>DateTime</returns>
public static System.DateTime ConvertIntDateTime(double d)
{
System.DateTime time = System.DateTime.MinValue;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
time = startTime.AddSeconds(d);
return time;
} /// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>double</returns>
public static double ConvertDateTimeInt(System.DateTime time)
{
double intResult = 0;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
intResult = (time - startTime).TotalSeconds;
return intResult;
}
}
}
由其是 soaringbird 呵呵
真的非常感谢
原来那个时间 是 1970 1 1 8 得加个小时