如何将整数转换为日期?

时间:2014-01-27 12:33:38

标签: c# javascript jquery timer

我创建了一个倒数计时器,如下所示:

enter image description here

我为startTime设置了manuel值

 var options = {
    stepTime: 60,

    format: "dd:hh:mm:ss",
    startTime: "01:12:32:55",
    digitImages: 6,
    digitWidth: 53,
    digitHeight: 77,
    image: "digits.png"
};

我在页面上有lblDay,lblHours,lblMinutes,LblSeconds。

我可以从SQL获取TotalHours列。如何将TotalHours的值转换为这样:

lbDays:27

lblHours:2

lblMinutes:34

lblSeconds:08




int TotalHours = Convert.ToInt32(dt.Rows[0][11]);

//int TotalHours =664

以及如何将标签值设置为startTime

1 个答案:

答案 0 :(得分:1)

int totalHours = 664; // example from question
TimeSpan ts = TimeSpan.FromHours(totalHours); // or similar
int days = (int)ts.TotalDays,
    hours = ts.Hours,
    // note the next will always be zero
    // since we init in an integer
    // number of hours
    minutes = ts.Minutes,
    seconds = ts.Seconds;