DateTime 转化成Byte数组 ,相反byte数组转化成Datetime?

liysky 2010-06-29 02:50:11
怎么将DateTime 转化成Byte数组 ,相反byte数组转化成Datetime? C#实现。
...全文
297 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
justfortemp 2010-07-21
  • 打赏
  • 举报
回复
时间处理的函数很多 条条大路
angel6709 2010-07-21
  • 打赏
  • 举报
回复
要用在网络上?
为什么不用BinaryStream
佳岳 2010-07-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 csu_dog 的回复:]
DateTime now = DateTime.Now;

byte[] bts = BitConverter.GetBytes(now.ToBinary());
DateTime rt = DateTime.FromBinary(BitConverter.ToInt64(bts, 0));
[/Quote]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CS.sql_manage
{
public partial class TestCode : Form
{
public TestCode()
{
InitializeComponent();
}

private void TestCode_Load(object sender, EventArgs e)
{
// DateTime dt = DateTime.Now;
// this.textBox1.Text = string.Format("{0:yyyyMMdd}",dt);
//this.textBox1.Text = dt.ToString("yyyyMMddHHmmss");
DateTime now = DateTime.Now;

byte[] bts = BitConverter.GetBytes(now.ToBinary());
DateTime rt = DateTime.FromBinary(BitConverter.ToInt64(bts, 0));
this.textBox1.Text = rt.ToString("yyyyMMddHHmmss");
}
}
}


测试通过
wangxu_518 2010-06-29
  • 打赏
  • 举报
回复
还有这么用的?学习~
csu_dog 2010-06-29
  • 打赏
  • 举报
回复
DateTime now = DateTime.Now;

byte[] bts = BitConverter.GetBytes(now.ToBinary());
DateTime rt = DateTime.FromBinary(BitConverter.ToInt64(bts, 0));

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧