日期:2014-05-18 浏览次数:20905 次
DateTime old = DateTime.Now; int date = 0; date = (date | old.Year - 2000) << 4; date = (date | old.Month) << 5; date = (date | old.Day); int time = 0; time = (time | old.Hour) << 6; time = (time | old.Minute) << 5; time = (time | old.Second); Int32 datetime = (date << 16) | time;
------解决方案--------------------
给你写出一个类,另一个你自己仿照着写就好了
public class myDate { private ushort _value; // 这个用于保存值 public int Year // 这个属性设置或读出年度码 { set { if (value <= 2099 || value >= 2000) { int temp = value % 100; _value = (ushort)((temp << 9) | (_value & 0x1ff)); } } get { return (_value & 0xfe00) >> 9; } } public int Month // 这个是月份 { set { if (value <= 12 || value >= 1) _value = (ushort)((value << 5) | (_value & 0xfe1f)); } get { return (_value & 0x1e0) >> 5; } } public int Day // 这个是日期 { set { if (value <= 31 || value >= 1) _value = (ushort)(value | (_value & 0xffe0)); } get { return _value & 0x1f; } } public string Value // 这个用于将指定格式的字符串装入本类对象,没做正确性检验的 { set { if (value.Length == 6) { Year = Int32.Parse(value.Substring(0, 2)); Month = Int32.Parse(value.Substring(2, 2)); Day = Int32.Parse(value.Substring(4, 2)); } } } }
------解决方案--------------------
应用myDate类的例子
static void Main(string[] args) { myDate md=new myDate(); md.Value = "121030"; Console.WriteLine(md.Year); Console.WriteLine(md.Month); Console.WriteLine(md.Day); }