65.9K
CodeProject 正在变化。 阅读更多。
Home

希捷日期代码计算器

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.22/5 (9投票s)

2007年8月6日

CPOL
viewsIcon

113890

downloadIcon

715

如何从数字 06212 得到日期 2005 年 11 月 20 日

Screenshot - SeagateDateCode.jpg

引言

本文描述的代码帮助用户将希捷(硬盘制造商)的日期代码转换为 DateTime 值。

本文基于 此文档

背景

我需要检查一些硬盘的保修情况,发现自己正在检查非常旧的硬盘。

代码

这是实际涉及的代码

类变量

private DateTime datecalc;
private string _datecode;

类属性

public string DateCode
{
    get { return _datecode; }
    set 
    {
        int _CodeYear = 0;
        byte _CodeWeek = 0;
        byte _CodeDayOfWeek = 0;
        _datecode = value;
        if (_datecode.Length == 5)
        {
            //Get the number of weeks to add
            _CodeWeek = Convert.ToByte(_datecode.Substring(2, 2));
            //Get the day of the week in the final week
            _CodeDayOfWeek = Convert.ToByte(_datecode.Substring(4));
        }
        else if (_datecode.Length == 4)
        {
            //Get the number of weeks to add
            _CodeWeek = Convert.ToByte(_datecode.Substring(2, 1));
            //Get the day of the week in the final week
            _CodeDayOfWeek = Convert.ToByte(_datecode.Substring(3));
        }
        if (_datecode.Length == 4 || _datecode.Length == 5)
        {
            _CodeWeek--;
            _CodeDayOfWeek--;
            _CodeYear = (2000 + Convert.ToInt32(_datecode.Substring(0, 2)) - 1);
            datecalc = new DateTime(_CodeYear, 7, 1);
            datecalc.AddDays(-1);
            do { datecalc = datecalc.AddDays(1); } 
            while (datecalc.DayOfWeek != DayOfWeek.Saturday);
            datecalc = datecalc.AddDays((_CodeWeek * 7) + _CodeDayOfWeek);
        }
    }
}

public DateTime CalculatedDate
{
    get { return datecalc; }
}

类构造函数

public SeagateDateCodeCalc()
{

}
public SeagateDateCodeCalc(string dateCode)
{
    this.DateCode = dateCode;
}

历史

这是我在这里的第一次提交,请告诉我是否遗漏了任何内容。

© . All rights reserved.